You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel like the example can be slightly confusing because the user provides both the hash to check and values used to calculate the known correct hash. And I'm not sure having a user-provided hash is that common, in my experience the user string is often a hash calculated from user-provided values.
I think it could be useful to add another about comparing a hash built from a user-provided password with a stored known hash of the correct password (which is a common scenario).
Maybe something like this:
<?php$knowPasswordHash = '$2y$10$4A9NKVnmZyGcdPKCgPE4o.2k0jHalnyyNEatk5hOIKFOUxB.ImI8y';
$sentPassword = $_POST['password]';
if (hash_equals($knowPasswordHash, password_hash($sentPassword)) {
echo"This is the correct password.", PHP_EOL;
} else {
echo"Wrong password.", PHP_EOL;
}
?>
(Of course you should use password_verify() for this specific use-case.)