Jump to content

log in script problem


steve490

Recommended Posts

Hey there,

 

Im trying to make a "email and password" log-in, on my site. I enter information into a form and it goes into the database (no problem there). When I try and log into the site it recognises the email but it doesn't recognise the password heres the code:- (sorry its a bit messy and long)

 


	connect to db

//checks if there is a cookie present
	if(isset($_COOKIE['ID_my_site']))

    //if there is, it logs the user in and directes them to the profile page
{
$email = $_COOKIE['ID_my_site'];
$password = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM table WHERE email = '$email'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($password != $info['pass'])
{
}
else
{
header("Location: profile.php");

}
}
}


//if the login form is submitted
if (isset($_POST['submit'])) { 

// this makes sure its been filled in
if(!$_POST['email'] | !$_POST['password']) {
die('Wrong username or password');

}
// checks whats been entered against the db

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM table WHERE email = '".$_POST['email']."'")or die(mysql_error());

//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('The information entered does not exist, please try again or. <a href=sign_up.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['password'] = stripslashes($_POST['password']);
$info['pass'] = stripslashes($info['pass']);
$_POST['password'] = md5($_POST['password']);

//gives an error if the password is wrong
if ($_POST['password'] != $info['pass']) {
die('Incorrect password, please try again.');
}

else
{
we add a cookie ready for the next time
}
}
}

Link to comment
Share on other sites

Hey thanks for replying,

 

Nomadrw... that didn't work it said that the user then didn't exist

 

ym_chaitu... it puts the password into the array... doesn't it?? im not hot with php lol, also i tried encrypting the passwords on my 'sign up' page so could this be why its not recognising the password? Although when i go into my database it hasn't encrypted them, it seems to be missing the code altogether, everything else on the page works. heres the encryption code

 

// here im encrypting the password and add slashes if needed to make it secure
$_POST['password'] = md5($_POST['password']);
if (!get_magic_quotes_gpc()) {
$_POST['password'] = addslashes($_POST['password']);
}

 

cheers if you need to see anything else, please let me know

Link to comment
Share on other sites

Although when i go into my database it hasn't encrypted them, it seemsto be missing the code altogether, everything else on the page works.heres the encryption code

 

this could be the problemm

as ur database has no encrypted passwrds and u are checking the encrypted password to the not encrypted ones it is giving this error

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.