Unable to login to Android app using hashed password

前端 未结 1 1667
温柔的废话
温柔的废话 2021-01-29 01:17

I have been following a tutorial in order to create a login for an Android based application, however after encrypting the passwords I am unable to get authenticate users. I hav

相关标签:
1条回答
  • 2021-01-29 02:06

    In login.php you should change this:

    //$passwordHash = password_hash($password, PASSWORD_DEFAULT); remove
    $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    

    Each time you hash the password it creates a unique hash (due to a randonly generated salt each time the function is run), so when you login and hash, you'll never get a match. You should instead use password_verify()

    Once you retrieve the password from the query, you can then verify:

    password_verify($password, $response['password']);
    
    0 讨论(0)
提交回复
热议问题