都不是.你应该用bcrypt
.您提到的散列都经过优化,在硬件上既快速又容易,因此破解它们具有相同的特性.如果您别无 Select ,至少要确保使用长盐并多次重新散列.
在PHP5.5中使用bcrypt+
PHP5.5提供new functions for password hashing.这是现代web应用程序中密码存储的推荐方法.
// Creating a hash
$hash = password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]);
// If you omit the ['cost' => 12] part, it will default to 10
// Verifying the password against the stored hash
if (password_verify($password, $hash)) {
// Success! Log the user in here.
}
如果您使用的是PHPyou really should upgrade的旧版本,但在使用之前,您可以使用password_compat公开此API.
另外,请让password_hash()
为您生成盐.它使用CSPRNG.
bcrypt的两个注意事项
- Bcrypt将自动截断任何超过72个字符的密码.
- Bcrypt将在任意
NUL
个字符后截断.
(此处的两个注意事项均为Proof of Concept.)
您可能会忍不住想在pre-hashing your passwords before running them through bcrypt之前解决第一个警告,但这样做可能会导致您的应用程序直接运行到第二个警告中.
不要编写自己的方案,而是使用由安全专家编写和/或判断的现有库.
TL;DR - Use bcrypt.