Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i give "0" for output
how i can understand the user o pass is correct or not?
C#
$user_name=$_POST['user_name'];
$password=md5($_POST['password']);
$con=mysql_connect("localhost","root","22646146");

mysql_select_db("bs",$con);
$query="select* from login  where user_name='$user_name' and password='$password'  LIMIT 1"; 
$result= mysql_query($query);

if($result)
{
     $num_rows=mysql_num_rows($result);
     echo $num_rows ;
}
else
{
     echo mysql_error();
}
?>
Posted
Updated 13-Aug-13 1:25am
v3
Comments
Jitendra Sabat 13-Aug-13 10:31am    
What is your objective?Whether you are trying to verify password for a particular user or what?Please clarify your question.
thanh_bkhn 13-Aug-13 10:42am    
Use echo to write down your SQL string, and paste into phpMyAdmin, then see the result, you can know if your log in information is correct or not.

Well, if mysql_num_rows returns a value greater 0 then your sqlquery apparently has found a matching record in the database and therefore the password must be correct.

(btw. do NOT store any password in clear text in the database. Better solution is i.e. to store the md5 of it and then compare the md5 of the entered password with it).
 
Share this answer
 
I guess, you are willing to check the encrypted password stored in database with md5 encryption is the one you are providing from user interface.I i am correct,then follow my code.

PHP
$user_name=$_POST['user_name'];
$rawpassword=$_POST['password'];
$password=md5($_POST['password']);
echo ("Entered password from user is:"+$rawpassword);
echo ("Entered password from user in encrypted form is:"+$password);
$con=mysql_connect("localhost","root","22646146");

mysql_select_db("bs",$con);
$query="select password from login  where user_name='$user_name' and password='$password'  LIMIT 1";
$result= mysql_query($query);
$finalObject=mysql_fetch_object($result);


if($finalObject.password == $password)
{
     echo "Password verified" ;
}
else
{
     echo "Password entered is wrong";
}
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900