Jump to content

Why is this not working?


chrisbasnett

Recommended Posts

Right, lil script to re-encrypt a users password on a login page and compare it to that saved within a database.

For some reason script doesn't seem to be working and i'm lacking in ideas on how to solve, any help would be appreciated.

 

Register.php

 

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("DB1", $con);

 

$user = strip_tags(substr($_POST['users_user'],0,32));

$pw = strip_tags(substr($_POST['users_password'],0,32));

$pw2 = strip_tags(substr($_POST['pw2'],0,32));

$cleanpw = crypt(md5($pw),md5($user));

 

$sql = "insert into users (users_username,users_password, users_Email)

values('".mysql_real_escape_string($user)."','".mysql_real_escape_string($cleanpw)."','$_POST[users_email]')";

 

if ($pw==$pw2)

{

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "User added, you may now login";

}

else echo "Error Passwords Do not match, please try again";

 

mysql_close($con)

?>

 

Note:Above script works, just a bit of background

 

Logincheck.php

 

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("db1", $con);

 

$user = strip_tags(substr($_POST['users_username'],0,32));

$pw = strip_tags(substr($_POST['users_password'],0,32));

$cleanpw = crypt(md5($pw),md5($user));

 

$sql = "select users_username, users_password from users

where users_username='". mysql_real_escape_string($user)."'

and users_username='". mysql_real_escape_string($cleanpw)."'

limit 1'";

$result = mysql_query($sql);

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

if (mysql_num_rows($result)){

echo "User found";

}else{

echo "User not found";

}

?>

 

The issue seems to be around the sql query itself.

The script after a bit of editing seems to work but fails to find the requested data when even after a manual check is in the database correctly. Any help would be much appreciated.

 

Chris

 

Link to comment
https://forums.phpfreaks.com/topic/149621-why-is-this-not-working/
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.