How to Verify Passwords with password_verify() in PHP

phplogo.jpg

In this lesson I will show you how to use password_verify() to validate a password from a user.

Consider the situation when a user password has been hashed (see this lesson) and stored in a database, and the user visits the site and enters their password as part of a login process.  We need to check the password the user has entered against the stored password.

In the previous lesson we saw that the plain text and hashed password details were:

To check the user input against the hashed password we use the password_verify() function as follows:

Line 3: this variable is simply acting as the user input

Line 5: this would be the stored hashed password

Line 7: we use password_verify to validate the input against the stored password

If you would like to learn more about using PHP then enrol in the PHP for Beginners course.