I'm upgrading my auth class, replacing md5
with crypt
for storing passwords. Here's the approach I've taken:
function crypt_pass($pass, $userID) {
$salt = $userID .'usesomesillystringforsalt'; // min 22 alphanumerics, dynamic
$method = (version_compare('5.3.7',PHP_VERSION,'>=')) ? '2y' : '2a'; // PHP 5.3.7 fixed stuff
if (CRYPT_BLOWFISH == 1) {
$blowfish_salt = '$'. $method .'$07$'. substr($salt, 0, CRYPT_SALT_LENGTH) .'$';
return crypt($pass, $blowfish_salt);
}
return sha1($pass . $salt);
}
Making the salt unique per user adds a step, a db lookup for the supplied username's id
... I figure it's worth it. Am I wrong about that? Is there anything else I'm not considering here?