Jump to content

need help with login


phpnoobie9

Recommended Posts

I'm able to submit username and sha1 password to my database, but can't seem to login.

 

Here is the login code. I'm always getting my else statement. Is there something I left out?

<php?
$username = trim(mysql_real_escape_string($_POST['username']));
$password = sha1(trim(mysql_real_escape_string($_POST['password'])));

if ( isset ($_POST['login'])) {
if ( (!empty ($_POST['username'])) && (!empty ($_POST['password'])) ) {
	if ( ($_POST['username'] == '$username') && ($_POST['password'] == '$password') ) {
		$_SESSION["loggedin"] = $_POST['username']; 
		header("location: member.php");
	} else {
		echo 'Username and password do not match.';
	}
}
}
?>

Link to comment
Share on other sites

<php?

Change <php? to <?php

 

$username = trim(mysql_real_escape_string($_POST['username']));

Why are you escaping the username? Do you do some DB call you aren't telling us about?

 

$password = sha1(trim(mysql_real_escape_string($_POST['password'])));

You shouldn't trim passwords. Maybe the person wants a space at the end of it

 

if ( (!empty ($_POST['username'])) && (!empty ($_POST['password'])) ) {

If you are storing the values into $username and $password, why are you still referring to the $_POST values?

 

if ( ($_POST['username'] == '$username') && ($_POST['password'] == '$password') ) {

First, $username and $password should not have single quotes around them. PHP interprets that as a literal string, not the value of a variable.

After that fix, this doesn't make any sense, because you are testing to see if a variable is equal to a copy of itself.

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.