I currently upgraded my server to PHP 5.5 and want to make good use of the new functions password_hash
and password_verify
.
I cant seem to get a hash to be verified correctly? I have copied the exact examples from the PHP manual and it still seems to be returning false
?
Is their something I am missing?
$hash = password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";
if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
returns
Invalid password.
You're appending a
\n
to your hash, which CHANGES the hash:Eliminate that, and it'll start working.