【发布时间】:2014-03-04 15:24:03
【问题描述】:
我通过互联网搜索并找到了哈希密码的功能。但是
我无法处理存储在数据库中的散列密码。我正在使用的函数生成随机密码,因为它与随机生成的盐连接。
当用户想要更改他的密码时,问题就出现了。
current_password = random hashed password( which must match the one stored in db).
if(current_password == $db_password){
enter new password
}
上述条件不成立,因为密码总是随机的。
我的功能
function cryptPass($input,$rounds = 9) {
$salt = "";
$saltChars = array_merge(range('A','Z'),range('a','z'),range(0,9));
for($i = 0;$i < 22; $i++){
$salt .= $saltChars[array_rand($saltChars)];
}
return crypt($input,sprintf('$2y$%02d$', $rounds).$salt);
}
$pass = "password";
$hashedPass = cryptPass($pass);
echo $hashedPass;
i have 3 column in my user table (id, username, password).
谁能告诉我如何正确使用这个功能, 或者有没有最好的方法来做到这一点?
【问题讨论】:
-
将盐与密码一起存储在表中。