I have read the other posts to this topic but haven't found a solution to this one. Here is my code, reduced to the bare functionality:
<?php
$password = "YS7Wde5s";
$hashA = password_hash($password, PASSWORD_BCRYPT);
echo $hashA . "<br>";
// Copied from echo above
$hashB = "$2y$10$nltCAZhbMD2OILgq2ftWNOd6kJL8oidQ12CLEM5Gi1kIj5GxKtNhm";
if (password_verify($password, $hashA)) {
echo "yes";
} else {
echo "no";
}
?>
The above code works well using $hashA
to verify the password. BUT:
- The echo of
$hashA
returns a different hash whenever I reload the page. - If I copy the echoed hash, hardcode it in
$hashB
, and use this instead of$hashA
, I never get a true out of thepassword_verify
call.
What am I missing? Is there an implicit type conversion I don't know about? Or am I completely wrong in how this should work?