我已经通过网络搜索过,发现哈希密码的函数。但
我有麻烦处理存储在数据库中的散列密码。我正在使用的函数会生成随机密码,因为它与随机生成的盐级联在一起。 用户想要更改密码时出现问题。哈希密码加盐
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).
任何一个可以告诉我如何正确使用此功能, 还是有做这一个最好的方法?
商店与密码一起在食盐。 –