PHP password_verify()

Udemy Generic 728x90

(PHP 5 >= 5.5.0)

Overview

If we are using the password hashing api of PHP 5.5, and we are securing our password with password_* functions, then of course we need a this function to verify the password to its hash.

So, it is quite useful in login process It takes the plain text password the user submitted during the login process, then detects the hashing method that was used to create the hash from the database, then hashes the submitted password using the same algorithm, and finally compares the two. It returns true if the password matches, and false otherwise.

Syntax
boolean password_verify ( string $password , string $hash )

  • $password
    • The user’s password.
  • $hash

Example

</p>
<p>&lt;?php</p>
<p>// See the password_hash() example to see where this came from.</p>
<p>$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';</p>
<p>&amp;nbsp;</p>
<p>if (password_verify('rasmuslerdorf', $hash)) {</p>
<p>echo 'Password is valid!';</p>
<p>} else {</p>
<p>echo 'Invalid password.';</p>
<p>}</p>
<p>?&gt;</p>
<p>

Udemy Generic 728x90

Spread the word. Share this post!