A large number of posts I've seen, regarding password hashing, says something along the lines of:
- Use a globally unique salt for each password
- Store salts in DB, alongside the hashed password
Dare I even say that this is the most common approach outlined?
It all makes sense - if you needed to rehash the input password each time - but in PHP you can use crypt
to verify a password, without ever using the salt. According to this post, it is "how it should be done".
For example:
$pass = 'YoiI8SjPAlFj';
$salt = '$2y$09$959d78f2f983628c711c7d';
echo $hashed = crypt($pass, $salt);
// $2y$09$959d78f2f983628c711c7O3YM7Xdl8Gdnh.S0C.ak41wA8RI1/3ga
And then to verify (using same vars)...
if(crypt($pass, $hashed) === $hashed) {
// Success
}else {
// Fail
}
Which will pass, just fine.
If that's the case, then why would I need to store the salt with my password? If the user changes their password, I'll generate a new salt anyway. It seems to me that the salt is superfluous information to store, and just takes-up memory.
Are there any arguments FOR storing it? 'Cause I can't think of any.