登录-用一个哈希值检查密码 [英] login - check password with hashed one
本文介绍了登录-用一个哈希值检查密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我要哈希的代码
This is my code to hash
class hashing {
private static $algo=''$2a'';
private static $cost=''$10'';
public static function unique_salt() {
return substr(sha1(mt_rand()),0,22);
}
function hash($password) {
return crypt($password,self::$algo.self::$cost.''$''.self::unique_salt());
}
public static function check_password($hash,$password) {
$full_salt=substr($hash,0,29);
$new_hash=crypt($password,$full_salt);
return ($hash==$new_hash);
}
}
这是我的登录页面
This is my login page
require("hashing.php");
$password=hashing::hash($_POST['txtPassword']);
$checkPassword=mysql_query("SELECT * from $tbl_name WHERE Password='".$password."'");
$resultPassword=mysql_fetch_row($checkPassword);
if(hashing::check_password($resultPassword['Password'],$_POST['txtPassword'])) {
echo "login success!";
}
else {
echo "login failed!";
}
用户输入正确的密码后,登录失败.我在哪里错了?
When the user inputs correct password, it is failing to login. Where am I wrong?
推荐答案
algo =''
2a''; 私人静态
2a''; private static
cost =''
这篇关于登录-用一个哈希值检查密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文