password_verify doesn't verify hash

前端 未结 2 629
孤城傲影
孤城傲影 2021-01-02 05:03

I hash my inserted passwords via password_hash. I verify them by using password_verify.

However when I insert a hashed password in my database and I try to verify it

相关标签:
2条回答
  • 2021-01-02 05:58

    You rehashed the password - just pass the plaintext password and your hash (from db) to password_verify and it works.

    0 讨论(0)
  • 2021-01-02 06:08

    The function password_verify(); takes two parameters; a non-hashed input, and a stored hash to compare it to. It hashes the non-hashed input automatically to compared it to the stored version. So your initial code was re-hashing an already hashed password. Should look like this:

    $verify=password_verify($_POST['passwrd'],$row[2]);
    
    if($verify){
        $_SESSION["usrname"]=$usrname;
        echo "Correct";
    }
    else {
        echo "user: " . $usrname. "<br>";
        echo "pass: " . $hash. "<br>";
        echo "db: " . $row[2]."<br>";
        echo "Wrong Username or Password";
    }
    
    0 讨论(0)
提交回复
热议问题