登录 - 使用哈希值检查密码(login - check password with hashed one)
IT问题网 2021-02-22 00:00:00
问 题
这是我的哈希代码
class hashing {
private static $ algo =''$ 2a'';
private static $ cost =''$ 10'';
public static function unique_salt(){
return substr(sha1(mt_rand()),0,22);
}
函数哈希($ password){
返回crypt($ password,self :: $ algo.self :: $ cost。''$''。self: :unique_salt());
}
公共静态函数check_password($ hash,$ password){
$ full_salt = substr($ hash,0,29);
$ new_hash = crypt($ password,$ full_salt);
return($ hash == $ new_hash);
}
}
这是我的登录页面
require(" hashing.php");
$ password = hashing :: hash($ _ post [' txtpassword']);
$ checkpassword = mysql_query(" select * from $ tbl_name where password ='"。$密码。" '");
$ resultpassword = mysql_fetch_row($ checkpassword);
if(hashing :: check_password($ resultpassword [' 密码'] ,$ _ post [' txtpassword'])){
echo " 登录成功!";
}
其他 {
echo " 登录失败!";
}
当用户输入正确的密码时,无法登录。我哪里错了?
解决方案
algo =''
2a'';
private static
cost =''
分享: