There are a variety of reasons why password_verify
could be returning false, it can range from the setup of your table to the actual comparing of the password, below are the common causes of it failing.
Column Setup
Password Sanitization
Another common cause is when developers try to “clean” the user’s password to prevent it from being malicious, as a result, this causes the input to be different to what is being stored in the table. It is not even necessary to escape the input, you should use prepared statements instead. You shouldn’t even trim
the passwords as that could change that which was originally provided.
Password Verification
When using password_verify
you need to compare the plaintext password with the hash from the database, not compare hashes (the implication here being that you need to have stored the hashed password of the user when they register):
Hardcoded Passwords
In the instance that you are using a hardcoded hash and you are facing issues, ensure that you are using single quotes instead of double quotes when storing the value in the variable as the $
will be interpreted in when using double quotes:
Repl – Comment out respectively.
Addendum
As per the documentation:
Caution It is strongly recommended that you do not generate your own salt for this function. It will create a secure salt automatically for you if you do not specify one.
As noted above, providing the salt option in PHP 7.0 will generate a deprecation warning. Support for providing a salt manually may be removed in a future PHP release.