My database stores the bcrypt passwords which means that the salt should be stored with in the password field. I don't want to make a separate field to store the salt by itself when it is not necessary. However when I want to compare passwords that the user sends to me to the passwords stored in the database, I need to hash the incoming password with the same salt. Question: what part of the stored hash is the salt? I think I could just return the salt using simple substr().
// password stored in database.
$user->password_hash = password_hash($password, PASSWORD_BCRYPT, array('cost' => 13));
// password from form being compared to form password
$form_password_hash = password_hash($data['form-password'], PASSWORD_BCRYPT, array('cost' => 13));
if($user->getPasswordHash() == $form_password_hash)
{
$user->setPassword($data['new-password']);
return new Response("Your password has been changed");
}
password_verify
does that for you. It does not generate a new salt, it uses the salt that's included with the hash you pass in. – CodesInChaos