简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM