Jump to content

Login Code Issue


csmcgoo

Recommended Posts

I have a pretty basic PHP log in code connected to a database of register users. However, it's not allowing any users to enter? Could someone please review the code and let me know if you find any errors?

 

	
//Create query
$qry="SELECT * FROM customers WHERE username='$login' AND password='".md5($_POST['password'])."'";

$result=mysql_query($qry);

//Check whether the query was successful or not
if($result) {
	if(mysql_num_rows($result) == 1) {
		//Login Successful
		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION['SESS_MEMBER_ID'] = $member['id'];
		$_SESSION['SESS_FIRST_NAME'] = $member['fname'];
		$_SESSION['SESS_LAST_NAME'] = $member['lname'];
		session_write_close();
		header("location: key_catalog.php");
		exit();
	}else {
		//Login failed
		header("location: login-failed.php");
		exit();
	}
}else {
	die("Query failed");
}
?>

Link to comment
Share on other sites

Since the echo is 32 characters, and the stored value is 40 characters, I'd venture a guess that it's a hashing method mismatch. More specifically, I'd bet that the value is inserted into the database with an SHA1 hash, in which case you'd need to use the same hashing algorithm to compare it.

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.