Jump to content

Login script not authenticating


omega1983

Recommended Posts

<?php 

//check for required fields from the form

if ((!$_POST['username']) || (!$_POST['password'])) {

  header("Location: auth1.php");   //header("Location: auth1.php");

    

    exit;


//set authorization cookie

  


$servername = "localhost";
$username = "tmc_user50";
$password = "Atl_344";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

$message="";
if(count($_POST)>0) {
    $conn = mysqli_connect("localhost","tmc_user50","Atl_344");
    $result = mysqli_query($conn,"SELECT * FROM admin2 WHERE username='" . $_POST["username"] . "' and password = '". $_POST["password"]."'");
    $count  = mysqli_num_rows($result);
    if($count==0) {
        $message = "Invalid Username or Password!";
    } else {
        $message = "You are successfully authenticated!";
    }
}

}

?>

When I enter any username ad password the code from auth2.php (the code above allows a connection anyway) I am attempting to redirect users back to auth1 if there is an incorrect username or password

Link to comment
Share on other sites

So little code yet so much wrong.

  1.  DO NOT USE PLAIN TEXT PASSWORDS. NOT NOW, NOT EVER!
  2.  Use Prepared Statements - NEVER EVER put variables in your query.
  3.  Do not SELECT *. Specify the column names you want
  4.  You need to check the REQUEST METHOD, not count the POST array
  5.  You have an extra closing curly bracket
  6.  Do not post your database login credentials for the whole world to see

 

Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.