password_verify doesn't verify hash

前端 未结 2 639
孤城傲影
孤城傲影 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 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. "
    "; echo "pass: " . $hash. "
    "; echo "db: " . $row[2]."
    "; echo "Wrong Username or Password"; }

提交回复
热议问题