[英]Can't fetch hashed password for login form in MySQL
I made a login form, and while the registration form is fully functional, the login form doesn't seem to be working. 我做了一个登录表单,虽然注册表格功能齐全,但登录表单似乎没有用。
$user
and $pwd
get declared, but $pwd_hashed
stayes empty. $user
和$pwd
,但是$pwd_hashed
空。
if(isset($_GET['login'])) {
$user = $_POST['user'];
$pwd = $_POST['pwd'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE user = :user");
$result = $stmt->execute(array('user' => $user));
$pwd_hash = $stmt->fetch();
if ($pwd_hash !== false && password_verify($pwd, $pwd_hash['password'])) {
$_SESSION['userid'] = $pwd_hash['id'];
die('Login successful<br>');
} else {
$errorMessage = "Username or password doesn't match<br>";
}
}
if(isset($errorMessage)) {
echo $errorMessage;
}
Should the code work like this and I just got something wrong with naming, or is there an error in the code? 代码是否应该像这样工作,我在命名时遇到了问题,或者代码中是否有错误?
This form is included in another site, in which a database was already selected. 此表单包含在另一个已选择数据库的站点中。 By removing it (
;dbname=test
) and specifying the users data base ( users.users
) the issue is gone. 通过删除它(
;dbname=test
)并指定用户数据库( users.users
),问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.