password_verify php not match

前端 未结 1 1814
旧时难觅i
旧时难觅i 2021-01-21 22:26

I try to check the password with the function password_verify with the posted user password and the hash from database.

First, how I generate the password and hash:

1条回答
  •  走了就别回头了
    2021-01-21 22:52

    Your $hash variable in your test case is invalid, and doesn't correspond to password

    $hash = '$2y$10$SwSq7OukPpN/QJ8YOdKgquJQ28fQbNY1Q3JdTFnoe.2VxD/D2RXBS';
    $password = '/f)1c(-JG';
    
    if (password_verify($password, $hash)) {
    echo 'Password is valid!';
    } else {
        echo 'Invalid password.';
    }
    

    When I used this code, everything works properly

    $password = '/f)1c(-JG';
    $hash = password_hash($password, PASSWORD_DEFAULT, array("cost" => 10));
    
    if (password_verify($password, $hash)) {
        echo 'Password is valid!';
    } else {
         echo 'Invalid password.';
    }
    

    I use php 5.5.10

    0 讨论(0)
提交回复
热议问题