0

When I tried to login, its always show "Incorrect Password" warning even when I have entered the right password.

Here is my login code

if(isset($_REQUEST['btn-login'])) {
    if(!empty($_POST)) {
        $username = $_POST['Username'];
        $password = $_POST['Password'];

        $check_stmt = $pdo->prepare('SELECT username,password FROM user WHERE username=?');
        $check_stmt->execute([$username]);
        $user_check = $check_stmt->fetch(PDO::FETCH_ASSOC);
    
        if($user_check > 0) {
            if(password_verify($password, $user_check['password'])) {
                $_SESSION['users'] = $username;
                header("location: home.php");
            } else {  
                Print '<script>alert("Incorrrect Password");</script>';
                Print '<script>window.location.assign("login.php");</script>';
            }
        } else {
            Print '<script type="text/javascript">alert("Username not found");</script>';
            Print '<script>window.location.assign("login.php");</script>';
        }
    } 
}

and this is the html form

<form action="login.php" method="POST">
    <label>Username : </label>
    <input type="text" name="Username" required></br>
    <label>Password : </label>
    <input type="password" name="Password" required></br>
    <input type="submit" name="btn-login" value="Login">
</form>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Rashal
  • 23
  • 4

0 Answers0