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