3 回答
![?](http://img1.sycdn.imooc.com/53339fdf00019de902200220-100-100.jpg)
TA贡献1853条经验 获得超9个赞
朋友,因为我们使用唯一的用户名登录,因此我们必须仅使用用户名从数据库中获取密码/数据。
例:
<?php
$connect = mysqli_connect($localhost, $username, $pwd, $database) or die("Opps some thing went wrong");
if (isset($_POST['submit'])) {
extract($_POST);
// Get Old Password from Database which is having unique userName
$sqlQuery = mysqli_query($connect, "select * from loginTable where User='$username'");
$res = mysqli_fetch_array($sqlQuery);
$current_password = $res['userPassword'];
if (password_verify($enteredPassword, $current_password)) {
/* If Password is valid!! */
$_SESSION['id'] = $res['id'];
header("location: home.php");
}
else {
/* If Invalid password Entered */
$alt = "Login Failed! Wrong user ID or Password";
header("location: index.php?m=$alt");
}
}
?>
它正在为我工作...我正在从数据库中获取密码,并使用PHP API与输入的密码进行比较,即password_verify($ enteredPassword,$ current_password)
![?](http://img1.sycdn.imooc.com/545869390001b87802200220-100-100.jpg)
TA贡献2041条经验 获得超4个赞
您让我检查数据库字段长度是正确的。不是255,那是打破它的原因。非常感谢您帮助我解决这个问题。我也在研究准备好的语句,我习惯于手动阻止SQL注入,直到最近我才听说过它们,到目前为止,我发现它们非常简单。再次感谢您的帮助。
- 3 回答
- 0 关注
- 947 浏览
添加回答
举报