Php login "Invalid username and password" using mysql

Muhd Elyas Bin Mohamed

I got 3 pages: success.html, login.php, checklogin.php. I also create a mysql database table called userInfo. The table "userInfo consist of 3 user: David, Jane, Richard. When I input the username and password using user David from userInfo then it direct to success.html and it will say "Login success". But when I input Mary for my username and mary for my password, it does not show me the message "Invalid Username and Password". The right output should have the message appeared on my browser because user Mary does not exist in the userInfo. But I don't know how to fix the problem.

Mysql Database "userInfo" :

show database

Success.html :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login Success Page - 156020K</title>
</head>

<body>
Login Success!!
</body>
</html>

Login.php :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>

<body>

<?php
    $url="http://localhost/156020K/Lab5?link=login.php";

    if(isset($_GET['link']))
    {
        echo "Invalid Username and Password";
    }
?>


<form action="checklogin.php" method="post">
    Username: &nbsp;
    <input type="text" name="uname">

    <br/>
    <br/>

    Password: &nbsp;
    <input type="password" name="pw">

    <br />
    <br />

    <input type="submit" value="Login">

</form>



</body>
</html>

Checklogin.php :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Check login</title>
</head>

<body>
<?php


  if(isset($_POST["uname"])) 
  {
      $u=$_POST['uname'];
      $p=$_POST['pw'];

      $conn=mysqli_connect("localhost", "root", "" , "db156020K");
      $sql = "SELECT * FROM userInfo WHERE name='" .$u. "' AND pass='" .$p. "' ";
      $search_result=mysqli_query($conn, $sql);

      $userfound=mysqli_num_rows($search_result);


      if($userfound >= 1)
      {
          header("Location: success.html");
      }
      else
      {
          header("Location: login.php");
      }


  }

  mysqli_close($conn);

 ?>



</body>
</html>

And the url should have request from the specified resource then it will passed back to login page when the authentication fails, it should be like this "../login.php?uname=Mary&pw=mary"

My Output:

click output <--- Does not show the invalid message when the username and password does not create from the userInfo mysql database

roberto06

Well, in your login.php file, you use :

if(isset($_GET['link']))
{
    echo "Invalid Username and Password";
}

to echo the error message, but in your checklogin.php file, you use :

header("Location: login.php");

to redirect if the login fails.

There is no $_GET parameter here, hence your error message will never bbe displayed. Try something like this for the redirect :

header("Location: login.php?link=whatever");

EDIT : Just saw this :

And the url should have request from the specified resource then it will passed back to login page when the authentication fails, it should be like this "../login.php?uname=Mary&pw=mary"

For this to happen, you have to use this redirect :

header("Location: login.php?uname=" . $u . "&pw=" . $p);

And check for these parameters in your login.php :

if(isset($_GET['uname']) && isset($_GET['pw']))
{
    echo "Invalid Username and Password";
}

But keep in mind that it's never a good idea to send passwords, even wrong ones, by $_GET.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP login "invalid username and password"

From Dev

Invalid username or password at login() using BlowfishPasswordHasher in CakePHP 2.x

From Dev

Invalid username and password on login, CakePHP 2.5.5

From Dev

Spring Boot, Spring Security, MySQL - CustomUserDetailsService always results in the error "Invalid Username or Password"

From Java

GitHub: invalid username or password

From Java

Sourcetree remote: Invalid username or password

From Dev

Invalid Username or Password in Codeigniter 3

From Dev

C# Error 401 - Invalid username or password

From Dev

Domino Web SSO : Invalid username or password was specified

From Dev

Google app engine launcher: Invalid username or password

From Dev

Cannot deploy with goapp - invalid username or password

From Dev

remote: Invalid username or password, fatal: Authentication failed for

From Dev

How to create a simple login in php using mySQL

From Dev

login program in Xcode using php and mysql is not working

From Dev

How to create a simple login in php using mySQL

From Dev

kuali - ORA-01017: invalid username/password; logon denied

From Dev

How to resolve unable to push to GitHub due to "Invalid username or password"?

From Dev

spring security bad credentials distinguish between invalid username or password

From Dev

How to throw an error for Invalid username or password if the data is not matched with the DB?

From Dev

Display Error message when connection or Invalid Username or Password in VBA

From Dev

Login using JQuery, PHP and MySQL data validation issue

From Dev

PHP login using details from two mysql tables

From Dev

Can not Make Android Login Using PHP, MySQL and Volley

From Dev

How to fetch last login datetime using PHP and MySQL database?

From Dev

php and MySQL Login system

From Dev

PHP MySQL Login Failure

From Dev

php mysql login issue

From Dev

php login form using if

From Dev

Login using ajax and php

Related Related

  1. 1

    PHP login "invalid username and password"

  2. 2

    Invalid username or password at login() using BlowfishPasswordHasher in CakePHP 2.x

  3. 3

    Invalid username and password on login, CakePHP 2.5.5

  4. 4

    Spring Boot, Spring Security, MySQL - CustomUserDetailsService always results in the error "Invalid Username or Password"

  5. 5

    GitHub: invalid username or password

  6. 6

    Sourcetree remote: Invalid username or password

  7. 7

    Invalid Username or Password in Codeigniter 3

  8. 8

    C# Error 401 - Invalid username or password

  9. 9

    Domino Web SSO : Invalid username or password was specified

  10. 10

    Google app engine launcher: Invalid username or password

  11. 11

    Cannot deploy with goapp - invalid username or password

  12. 12

    remote: Invalid username or password, fatal: Authentication failed for

  13. 13

    How to create a simple login in php using mySQL

  14. 14

    login program in Xcode using php and mysql is not working

  15. 15

    How to create a simple login in php using mySQL

  16. 16

    kuali - ORA-01017: invalid username/password; logon denied

  17. 17

    How to resolve unable to push to GitHub due to "Invalid username or password"?

  18. 18

    spring security bad credentials distinguish between invalid username or password

  19. 19

    How to throw an error for Invalid username or password if the data is not matched with the DB?

  20. 20

    Display Error message when connection or Invalid Username or Password in VBA

  21. 21

    Login using JQuery, PHP and MySQL data validation issue

  22. 22

    PHP login using details from two mysql tables

  23. 23

    Can not Make Android Login Using PHP, MySQL and Volley

  24. 24

    How to fetch last login datetime using PHP and MySQL database?

  25. 25

    php and MySQL Login system

  26. 26

    PHP MySQL Login Failure

  27. 27

    php mysql login issue

  28. 28

    php login form using if

  29. 29

    Login using ajax and php

HotTag

Archive