I have setup my password hashing using PHP password_*
functions
1) password_hash($password, PASSWORD_BCRYPT, array("cost" => 11);
2) return password_verify($password, $hashedPassword)? true : false;
Everything work fine.
I found also password_needs_rehash() function, which tak 2 params, $hashedPassword and algorithm, example:
password_needs_rehash($hashedPassword, PASSWORD_BCRYPT);
I understand to use this when it's changed algorithm or cost, something like:
if (!password_verify($password, $hashedPassword)) {
return false;
}
if (password_needs_rehash($hashedPassword, PASSWORD_BCRYPT)) {
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
// update user password in database with $hashedPassword
}
return true;
Everything it's clear, I have just a doubt.
I try change the cost, without calling password_needs_rehash() function, and I am able to login.
I try also change on my function which generate hash, I change algorithm from PASSWORD_BCRYPT to PASSWORD_DEFAULT.
I am always able to login.
Can someone explain how does it work?
If we don't re-hash when algorithm change, how PHP password_* handle this?
PS A small question into question... Using php function_* does it raccomanded to use "salt" for password or not?
Thanks!!