作者:天堂调度长 | 来源:互联网 | 2023-05-16 16:08
WhenIclicksubmit,theinputvalidationworks,butevenwhenItypeintheusernameandpasswordc
When I click submit, the input validation works, but even when I type in the username and password correctly that is stored in my database exactly as I'm entering it, with consideration of the hash, but all I get is the error message telling me the combination is incorrect.
当我单击提交时,输入验证可以正常工作,但即使我正确地输入存储在我的数据库中的用户名和密码,就像我输入它一样,考虑到哈希,但我得到的只是错误消息告诉我的组合是不正确的。
This is my login script:
这是我的登录脚本:
$username = $_POST['username'];
$password = $_POST['password'];
if (isset($_POST['submit']) === true) {
$login = login($username, $password);
if (empty($username) === true || empty($password) === true) {
$errors[] = "Please fill in all fields";
} elseif ($login === false) {
$errors[] = "That username and password combination is incorrect";
} else {
$_SESSION['login'] = $login;
echo 'Logged in';
}
}
And here are the functions:
以下是功能:
function login($username, $password) {
global $conn;
$query = "SELECT userId FROM users where userName = '$username' AND userPass = '$password'";
$result = mysqli_query($conn, $query);
$row_count = mysqli_num_rows($result);
if ($row_count >= 1) {
return $query['userId'];
} else {
return false;
}
}
enter image description here
在此处输入图像描述
3 个解决方案