• PHP Video Tutorials

PHP password_verify() Function



The password_verify() function can verify that a password matches a hash.

Syntax

boolean password_verify( string $password , string $hash )

The password_verify() function can verify that given hash matches the given password.

Note that the password_hash() function can return the algorithm, cost, and salt as part of a returned hash. Therefore, all information that needs to verify a hash that includes in it. This can allow the password_verify() function to verify a hash without need separate storage for the salt or algorithm information.

The password_verify() function can return true, if the password and hash match, or false otherwise.

Example 1

<?php
   $passw01 = "53nh46u74m3nt3";
   $hashp02 = '$argon2i$v=19$m=1024,t=2,p=2$d1JJWnNHMkVEekZwcTFUdA$zeSi7c/Adh/1KCTHddoF39Xxwo9ystxRzHEnRA0lQeM';

   $test02 = password_verify($passw01, $hashp02);
   
   if($test02 == true) {
      echo "VALID password for the informed HASH!<br>"; 
      var_dump($test02);
   } else {
      echo "INVALID password for the informed HASH!<br>";     
      var_dump($test02);    
   }
?>

Output

INVALID password for the informed HASH!<br>bool(false)

Example 2


Output

VALID password for the informed HASH!<br>bool(true)
<br><br>algo = argon2i<br>algoName = argon2i<br>memory_cost = 1024<br>time_cost = 2<br>threds = 2<br><br> 
php_function_reference.htm
Advertisements