Sylverdrag Sylverdrag - 5 months ago 372
PHP Question

PHP password_verify() not working

Sorry all, this is just a stupid typo and I can't delete the question because there is an answer.

I am quite puzzled by this one. Originally tried matching the result from the database. When that didn't work, I tried feeding directly the result of the hashing function into password_verify() and that doesn't work either:

$pass = "password";
$hash = password_hash($password, PASSWORD_DEFAULT);
if (password_verify($pass, $hash))
{
echo "Ok, that worked";
}
else
{
echo "WTF?";
}


A hash is produced, but password_verify() returns false.

My PHP version is 5.5.9.

Answer

You're using $pass and $password. Two separate variables.

$pass = "password";
$hash = password_hash($pass, PASSWORD_DEFAULT);
if (password_verify($pass, $hash))
{
    echo "Ok, that worked";
}
else
{
    echo "WTF?";
}
Comments