如何在 PHP 中使用 Blowfish 创建和存储密码哈希
1) 如何使用 crypt() 创建安全的 Blowfish 密码哈希?
$hash = crypt('somePassword', '$2a$07$nGYCCmhrzjrgdcxjH$');
1a) $2a"的意义是什么?它只是表明应该使用 Blowfish 算法吗?
1b) $07"的意义是什么?较高的值是否意味着更安全的哈希?
1c) $nGYCCmhrzjrgdcxjH$"的意义是什么?这是要使用的盐吗?这应该是随机生成的吗?硬编码?
1a) What is the significance of "$2a"? Does it just indicate that the Blowfish algorithm should be used?
1b) What is the significance of "$07"? Does a higher value imply a more secure hash?
1c) What is the significance of "$nGYCCmhrzjrgdcxjH$"? Is this the salt that will be used? Should this be randomly generated? Hard-coded?
2) 如何存储 Blowfish 哈希?
echo $hash;
//Output: $2a$07$nGYCCmhrzjrgdcxjH$$$$.xLJMTJxaRa12DnhpAJmKQw.NXXZHgyq
2a) 其中哪一部分应该存储在数据库中?
2b) 列(MySQL)应该使用什么数据类型?
2a) What part of this should be stored in the database?
2b) What data type should be used for the column (MySQL)?
3) 应该如何验证登录尝试?
推荐答案
你应该存储 crypt 的整个输出,拆分它没有太大意义,因为你需要为你的每个密码生成一个新的 salt无论如何都要重新散列.使用 Matt 提到的固定隐藏盐是错误的 - 每个哈希的盐应该不同.
You should store the entire output of crypt, there's not a lot of point in splitting it up, because you need to generate a new salt for each password you're hashing in any case. Using a fixed hidden salt as mentioned by Matt is wrong - the salt should be different for every hash.
有关详细信息,请参阅 http://www.openwall.com/articles/PHP-用户密码 - 我推荐使用 phpass 库,因为它会为您生成随机盐,这与 crypt() 不同.
For more information see http://www.openwall.com/articles/PHP-Users-Passwords - I recommend using the phpass library because it handles generating a random salt for you, unlike crypt().
相关文章