Jump to content

Login Issues


EoNSteve
Go to solution Solved by EoNSteve,

Recommended Posts

Hello,

 

I am working on a login script and before I even touch the sessions/cookies, I am getting an error.

 

Code below:

if (isset($_POST["postlogin"]) && !empty($_POST["postlogin"])) {
require_once('config.php');

    
mysql_connect("$dbhost", "$dbuser", "$dbpasswd") 
or die(mysql_error());  mysql_select_db("$dbname") 
or die(mysql_error());  
   
    $subuname = $_POST['asuname'];
    $subupass = md5($_POST['asupass']);
echo $subuname;
echo $subupass;

$loginsql = mysql_query("select * from users where u_name='$subuname'") or die(mysql_error());
$loginresult = mysql_fetch_array($loginsql);
echo $loginresult['u_name']."<BR>";

//if (mysql_num_rows($loginresult) > 0 )
if (($loginresult['u_name'] == '$subuname') && ($loginresult['u_pass'] == '$subupass'))
{
echo "it worked";
}
else
{
echo "login failed";
}

Regardless of whether the login information is successful or fails, I get a 'login failed'. Anyone see why? I have a bunch of random echos to show where the values are and they all seem correct.

Link to comment
Share on other sites

Variables don't work within single-quoted strings. Try changing this

if (($loginresult['u_name'] == '$subuname') && ($loginresult['u_pass'] == '$subupass'))

to this

if (($loginresult['u_name'] == $subuname) && ($loginresult['u_pass'] == $subupass))
Edited by cyberRobot
Link to comment
Share on other sites

Side notes:

Link to comment
Share on other sites

I am getting that I need to use PDOs. Time to learn something new I guess.

 

I am planning to use real_escape once I get the rest of the coding complete, right now I just want to get it working.

 

I have already made teh change to SHA1 from MD5.

Edited by EoNSteve
Link to comment
Share on other sites

I am planning to use real_escape once I get the rest of the coding complete, right now I just want to get it working.

 

No, you need to use prepared statements, and correct queries are an essential part of getting your code to work.

 

You cannot keep your errors and at the same time expect the code to function properly. That should be obvious.

 

 

 

I have already made teh change to SHA1 from MD5.

 

Which doesn't help you one bit. Did you read cyberRobot's response? Neither MD5 nor SHA-1 nor any similar algorithm was ever designed for password hashing. They can be easily attacked with a standard PC at a rate of billions(!) of calculations per second.

 

It's the year 2017. We use bcrypt now.

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.