我无法安全地验证用户名和密码。在检查数据库中是否存在电子邮件地址后,我检查输入的密码是否与数据库中的密码匹配,但我的密码没有验证。
这是我的user\u login.php文件:
require_once "../include/Constants.php";
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if($_SERVER['REQUEST_METHOD']=='POST')
{
$username = $_POST['username'];
$password = $_POST['password'];
//filter this variable for security
$password = strip_tags(mysqli_real_escape_string($conn, trim($password)));
$query = "SELECT * FROM students WHERE s_id = '".$username."' ";
$tbl = mysqli_query($conn, $query);
if(mysqli_num_rows($tbl)>0)
{
//when email is matched it also need to verify the password
$row = mysqli_fetch_array($tbl);
$password_hash = $row['password'];
if(password_verify($password, $password_hash))
{
echo "success";
}
else
{
echo "failed login"."<br/>";
echo $password_hash."<br/>";
echo $password;
}
}
else
{
echo "email failed";
}
由于某些原因,密码和用bcrypt加密的密码不匹配。我找不到我做错了什么。如果您有一些关于解决方案的建议,请提供帮助。谢谢!
1条答案
按热度按时间3lxsmp7m1#
就目前的情况而言,你需要改变
mysqli_fetch_array()
到mysqli_fetch_array($tbl, MYSQLI_ASSOC)
,因为仅此操作就获取了错误的数组类型。没有具体的论据,它(
mysqli_fetch_array()
)默认为MYSQLI_BOTH
,是一个关联的数字数组。php可能试图访问错误的相关列。