php-比较散列和散列的mysql密码时出错(输出值相等)
作者:互联网
我正在尝试将mysql数据库中的哈希密码值与从登录表单输入的密码的哈希值进行比较.
但是,当我比较两个值时,它表示它们不相等.我将盐简单地去除了,然后测试输出是什么,并得到相同的值
$password1 = $_POST['password'];
$hash = hash('sha256', $password1);
...connect to database, etc...
$query = "SELECT *
FROM users
WHERE username = '$username1'";
$result = mysql_query($query);
$userData = mysql_fetch_array($result);
if($hash != $userData['password']) //incorrect password
{
echo $hash."|".$userData['password'];
die();
}
...other code...
样本输出:
7816ee6a140526f02289471d87a7c4f9602d55c38303a0ba62dcd747a1f50361 | 7816ee6a140526f02289471d87a7c4f9602d55c38303a0ba62dcd747a1f50361
有什么想法吗?
解决方法:
我遇到了完全相同的问题. var_dump()告诉我,我有两个具有相同属性的变量string(128).我能够进行比较的唯一方法是将哈希值转换为字符串:
$password1 = $_POST['password'];
$hash = (string)hash('sha256', $password1);
...
$userData = (string)mysql_fetch_array($result);
if($hash == $userData) {
//This should return true.
}
标签:string-comparison,hash,mysql,php 来源: https://codeday.me/bug/20191208/2089310.html