目前认为MD5是部分不安全的。考虑到这一点,我想知道使用哪种机制来保护密码。
这个问题,“双重哈希”密码是否比只哈希一次更不安全?
建议哈希多次可能是一个好主意,而如何实现个别文件的密码保护?建议使用盐。
我用的是PHP。我想要一个安全快捷的密码加密系统。对一个密码进行一百万次哈希运算可能更安全,但也更慢。如何在速度和安全之间取得良好的平衡?此外,我更希望结果具有恒定数量的字符。
哈希机制必须在PHP中可用
必须是安全的
它可以使用盐(在这种情况下,所有的盐都一样好吗?有没有办法生产出好的盐?)
另外,我是否应该在数据库中存储两个字段(例如,一个使用MD5,另一个使用SHA)?这会让它更安全还是更不安全?
以防我不够清楚,我想知道要使用哪个哈希函数,以及如何选择一个好的盐,以便拥有一个安全和快速的密码保护机制。
没有完全涵盖我的问题的相关问题:
PHP中的SHA和MD5有什么区别
简单密码加密
为asp.net存储密钥和密码的安全方法
如何在Tomcat 5.5中实现加盐密码
我使用的是Phpass,这是一个简单的单文件PHP类,可以在几乎每个PHP项目中非常容易地实现。参见The H。
默认情况下,它使用在Phpass中实现的最强可用加密,即bcrypt,并回落到其他加密,直到MD5,以提供向后兼容的框架,如Wordpress。
返回的散列可以按原样存储在数据库中。生成哈希的示例使用如下:
$t_hasher = new PasswordHash(8, FALSE);
$hash = $t_hasher->HashPassword($password);
要验证密码,可以使用:
$t_hasher = new PasswordHash(8, FALSE);
$check = $t_hasher->CheckPassword($password, $hash);
我通常使用SHA1和salt和用户ID(或其他特定于用户的信息),有时我还使用常数salt(因此我有2部分salt)。
SHA1 is now also considered somewhat compromised, but to a far lesser degree than MD5. By using a salt (any salt), you're preventing the use of a generic rainbow table to attack your hashes (some people have even had success using Google as a sort of rainbow table by searching for the hash). An attacker could conceivably generate a rainbow table using your salt, so that's why you should include a user-specific salt. That way, they will have to generate a rainbow table for each and every record in your system, not just one for your entire system! With that type of salting, even MD5 is decently secure.
好吧
在fitsy,我们需要盐
盐必须是独一无二的
我们来生成它
/**
* Generating string
* @param $size
* @return string
*/
function Uniwur_string($size){
$text = md5(uniqid(rand(), TRUE));
RETURN substr($text, 0, $size);
}
我们还需要哈希值
我使用sha512
它是最好的,而且是用PHP编写的
/**
* Hashing string
* @param $string
* @return string
*/
function hash($string){
return hash('sha512', $string);
}
所以现在我们可以使用这个函数来生成安全的密码
// generating unique password
$password = Uniwur_string(20); // or you can add manual password
// generating 32 character salt
$salt = Uniwur_string(32);
// now we can manipulate this informations
// hashin salt for safe
$hash_salt = hash($salt);
// hashing password
$hash_psw = hash($password.$hash_salt);
现在我们需要在数据库中保存$hash_psw变量值和$salt变量
对于授权,我们将使用相同的步骤…
这是保护客户密码的最好方法……
另外,最后两个步骤你可以使用自己的算法…
但是要确保将来可以生成这个散列密码
当您需要授权用户…