我找到了这个示例如何使用 PHP 散列和检查密码。这安全吗?这是模仿的好例子吗?
public function hashPassword($mail, $password, $salt, $rounds='08')
{
$length = strlen($password) * 4;
$data = str_pad($password, $length, sha1($mail), STR_PAD_BOTH);
$string = hash_hmac('whirlpool', $data, SERVER_KEY, true);
return crypt($string, '$2a$' . $rounds . '$' . $salt);
}
public static function checkPassword($mail, $password, $stored)
{
$length = strlen($password) * 4;
$data = str_pad($password, $length, sha1($mail), STR_PAD_BOTH);
$string = hash_hmac ('whirlpool', $data, SERVER_KEY, true);
return (crypt($string, substr($stored, 0, 30)) === $stored);
}