Jump to content

Login Issues


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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.