我在php中创建一个登录/注册系统 . 我在密码验证方面遇到了大问题 . 我在注册时散列用户的密码,但是password_verify函数不起作用 . 在下面的代码中你可以看到我试图得到一个答案是否获得密码...我总是得到“错误”作为答案... $ email = mysqli_real_escape_string($ con,$ _ POST ['email' ]); $ password = mysqli_real_escape_string($ con,$ _ POST ['password']);
$result=mysqli_query($con,"SELECT * FROM users WHERE
email='$email'");
$count=mysqli_num_rows($result);
$pass=mysqli_fetch_assoc(result);
if($count == 1)
{
if(password_verify($password,$pass['password']))
{
$_SESSION['email']=$email;
if($checkBox="on")
{
setcookie("email",$email,time()+3600);
}
header("location: profile.php");
}
}
else {
$error="Error with either the email or the password";
}
2 回答
Try this
在您的查询中,您不能比较密码 . 因为多个用户可能具有相同的密码 . 而是使用电子邮件ID获取密码 .
在比较/验证密码之前,请对从请求中获取的密码进行哈希处理 .
所以你的代码就像:
Edited Code
试试这个: