[英]Comparing Hashed Password in the database to user Input in PHP MYSQLI
How do I compare hashed passwords that are stored in the database to a user inputted password, I need to do thsi so that the user could log in. 如何将存储在数据库中的哈希密码与用户输入的密码进行比较,我需要这样做,以便用户可以登录。
Here's how I hashed my password (using phps crypt method) 这是我对密码进行哈希处理的方式(使用phps crypt方法)
$hashedpass = crypt($password);
$sql = "INSERT INTO accounts (username,password,email) VALUES('{$username}','{$hashedpass}','{$email}')";
$conn->query($sql);
This is how I compare them to user input 这就是我将它们与用户输入进行比较的方式
$username = trim($_POST['username']);
$password = crypt($_POST['password']);
$sql = "SELECT * FROM accounts WHERE username = '{$username}' && password = '{$password }'LIMIT 1";
echo "$sql";
$rs = $conn->query($sql);
$numRows = $rs->num_rows;
if($numRows == 1){
echo "you may log in";
}
I am 100% sure that I enterd the password correctly but the thing is mysql is not showing results, 我100%确定我正确输入了密码,但问题是mysql没有显示结果,
看看crypt的PHP文档 ,因为您没有提供SALT值,您将获得存储结果,通常结果是一个值的哈希值与另一个相同值的哈希值不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.