Search code examples
phppassword-hash

How to verify an hashed password


I am using the password_hash() function.

Now it works to hash the password, but how do I verify it?


Solution

  • Well the function for this option is called: password_verify.

    How it does work is this;

    <?php
    $password = "[PASS]"; //Password user fill in.
    $hash= "[HASH]"; //The hashed password that you saved.
    $checkPass = password_verify($password, $hash); //This returns a boolean; true or false
    if ($checkPass == true)
    {
      echo 'Password is good!';
    }
    else
    {
      echo 'Password is wrong!';
    }
    ?>