我最近开始研究一个项目,它包含以下哈希密码函数:
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);
干杯!
答案 0 :(得分:0)
使用帐户ID作为盐可能不是一个好主意 - 如果有人可以窃取您的哈希密码,那么他们也可能获得帐户ID。因此,如果代码也受到良好保护,则在此实例中在代码中具有更复杂的散列可能更安全。使用已知的随机字符串作为代码中的salt意味着有人必须破解您的数据和代码才能攻击密码 - 这必须比仅仅攻击数据库更好。