【发布时间】:2012-06-11 13:10:04
【问题描述】:
我最近开始了一个项目,它包含以下哈希密码的函数:
function hash_password($password) {
$account_id = $this->account_id;
/*
* Cook up some randomness
*/
$password = str_rot13($password);
$random_chars = "1%#)(d%6^".md5($password)."&H1%#)(d%6^&HB(D{}*&$#@$@FEFWB".md5($password)."``~~+_+_O(Ed##fvdfgRG:B>";
$salt = $account_id;
$salt = ((int)$salt * 123456789) * 1000;
$salt_len = strlen($salt);
for($i=0; $i <= $salt_len; $i++) {
$salt .= $random_chars[$i];
}
$salt = str_repeat($salt, 3);
return hash('sha256', base64_encode($password.$salt.$password), false);
}
*$account_id 对于每个用户帐户都是唯一的。
我的问题是:这个功能是否比做一些简单的事情更安全:
$salt = sha1($account_id);
$hash = hash('sha256', base64_encode($password.$salt), false);
干杯!
【问题讨论】:
-
你使用什么散列算法并不重要,只要你正确地加盐。即使是 SHA1 也可以使用良好的盐非常安全。
-
Is this function any more secure- 是的,但是Is this hashing function overkill- 绝对是的。您正在使用 大量 的 CPU 周期来对密码进行哈希处理 - 每次 您处理登录或用户更改密码时都需要这样做 [, 或。 ..] 而您应该更关注的是(如果他们那么敏感的话)是防止人们首先获得散列密码。 -
实际上它可能不太安全,因为熵要高得多 - 看到这个grc.com/haystack.htm - 你应该使用
bcrypt无论如何
标签: php hash passwords password-protection sha