php - Password Hashing issue with password_hash & password_verify
I currently upgraded my server to PHP 5.5 and want to make good use of the new functionspassword_hash
andpassword_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 returningfalse
?
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.
Answer
Solution:
You're appending a
\n
to your hash, which CHANGES the hash:Eliminate that, and it'll start working.
Answer
Solution:
I think the problem is that you are appending a new line with
'\n'
at the end.They are using that to add a newline to the output in the examples.