Jump to content

unable to login


nadeem14375

Recommended Posts

Dear all,

 

I am new to PHP. here I want to develop a login page. what's wrong in the following page?

 

<?php

include ('/includes/dbConfig.php');

session_start();

// username and password sent from form

$email=$_POST['email'];

$password=md5($_POST['password']);

 

// To protect MySQL injection (more detail about MySQL injection)

$email = mysql_real_escape_string($email);

$password = mysql_real_escape_string($password);

 

$query="SELECT * FROM member_info WHERE email='$email' and password='$password'";

 

$result=mysql_query($query);

 

if (mysql_num_rows($result) != 1) {

//$error = "Bad Login";

echo "Bad Login";

 

}

else

{

header("location:index.php");

}

?>

 

Regards:

Muhammad Nadeem

Link to comment
Share on other sites

yep. unless I'm missing something, code seems fine to me.

what exactly is the error? you just asked if there was anything wrong but you never told us what was happening when you try to login.

 

are you sure the stored passwords were also encrypted with md5() ? are you sure you're using the correct password?

 

set one of the passwords to 123, remove the md5() line and test again just to be sure.

 

Link to comment
Share on other sites

ok, try this:

remove and password='$password' from your $query

then go back to your original code and change this:

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
echo "Bad Login";
}

 

for this:

 

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
   echo "Bad Login: Cannot find that email";
}else{
   echo "Must be wrong password";
}

 

 

Also, keep in mind that mysql_num_rows($result) != 1 checks to see if the result is 1 row. If that emails exists more than once in the database this will also fail because num_rows will be 2 or more.

Hope this helps

Link to comment
Share on other sites

dear,

 

without md5, its ok.

but when i store in database with md5, the i couldn't be able to login, as i mentioned.

 

1. before insertion convert to md5(). the password is now encrypted.

 

2. login time , before selecting from database, md5().

or

only select from database. both don't let me to login.

 

What's the problem?

 

 

ok, try this:

remove and password='$password' from your $query

then go back to your original code and change this:

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
echo "Bad Login";
}

 

for this:

 

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
   echo "Bad Login: Cannot find that email";
}else{
   echo "Must be wrong password";
}

 

 

Also, keep in mind that mysql_num_rows($result) != 1 checks to see if the result is 1 row. If that emails exists more than once in the database this will also fail because num_rows will be 2 or more.

Hope this helps

Link to comment
Share on other sites

in that case, I'm guessing your database password field is not long enough for md5 hashes and they're being truncated (cut off) when inserted. You need 32 characters to store an md5 encrypted string.

 

check if password field is varchar (32)

 

 

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.