Jump to content

[SOLVED] Login Form - Password check not working


MasterACE14

Recommended Posts

I have a Login Script, and it has been working fine, except I just realised its been missing one thing, a password check !!! (don't ask me how I missed that  :P). I'm trying to put the password check in, but its just not working for me, even though the password put in is correct, here's my script:

 

<?php

$username = addslashes($_POST["username"]);
$email = addslashes($_POST["email"]);
$password = addslashes(md5($_POST["password"]));

echo $password;

if (empty($username) || empty($email) || empty($password)) {
  echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br>
    <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
  die();
}

mysql_connect( "localhost", "ace_ACE", "*****" );
mysql_select_db( "ace_cf" );

$pass_check = "SELECT `password` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1";
$pass_you = mysql_query( $pass_check );
if($password !== $pass_you) { echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
            <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
            die(); }

$sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1";
if ($rs = mysql_query( $sql )) {
  if (mysql_num_rows($rs)) {
    $row = mysql_fetch_assoc($rs);
    $_SESSION['username'] = $username;
    $_SESSION['playerid'] = $row['id'];
    header("Location: index.php?page=base");
  } else {
    echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
            <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
            die();
  }
} else {
  die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());
}

?>

 

I put in the correct password, I echo the password, its correct. When I compare it to the database. So why isn't it working?

 

it keeps dieing and displaying:

Their is no Account matching the Username, Password and E-mail address you entered

 

Regards ACE

Link to comment
Share on other sites

There is a fair amount of redundancy in your code. Your running two almost identical queries for no reason.

 

<?php

 if (isset($_POST['submit'])) {
   $username = addslashes($_POST["username"]);
   $email = addslashes($_POST["email"]);
   $password = addslashes(md5($_POST["password"]));

   if (empty($username) || empty($email) || empty($password)) {
     echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br>
     <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
     die();
   }

   mysql_connect( "localhost", "ace_ACE", "*****" );
   mysql_select_db( "ace_cf" );

   $sql = "SELECT id FROM `cf_users` WHERE `username` = '$username' && `password` = '$password' && `email` = '$email' LIMIT 1";
   if ($result = mysql_query($sql)) {
     if (mysql_num_rows($result)) {
       $row = mysql_fetch_assoc($result);
       $_SESSION['username'] = $username;
       $_SESSION['playerid'] = $row['id'];
       header("Location: index.php?page=base");
     } else {
       echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
         <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
         die();
     }
   } else {
     echo "Query failed<br />" . mysql_error() . "<br />$sql";
   }

?>

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.