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.';


Invalid password.



You're appending a\n to your hash, which CHANGES the hash:

$hash = password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";

Eliminate that, and it'll start working.




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.

People are also looking for solutions to the problem: php - How can I copy rows from one to another table with a different number of columns


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.