Hi
I am using the code below to validate user when they login to my website, the first part check if user have typed their username and the second part search the table to check user exist. These two parts work fine but the last part the while condition don’t work it keep give me the error massage “You provided an incorrect password. Please try again.”
Any help?
Regards
HB 25
<?php
// Have they entered a ClientID?
if(empty($_POST['username']))
{
die("Please enter your correct username.");
}
$con = mysql_connect("xxxxxx","xxxxxx","xxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxx", $con);
// Get variables from the previous page. Remove possible hack attempts.
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
// Build the query used to see if that account exists.
$query = "SELECT `username`,`password` FROM tbluser WHERE `username`='".$username."'";
$result = mysql_query($query);
// If the records returned isn't exactly 1, then that username doesn't exist. Or, there may be a strange glitch where two users have the same name, but the registration script will get rid of any chance of that anyway.
if(mysql_num_rows($result)!=1)
{
die('We don\'t have a user called '.$username.'. If this is your first visit to our website, you may need to <a href="../register.htm">create an account</a>. Otherwise, check your spelling.');
}
// Now, validate the password.
while($record = mysql_fetch_assoc($result))
{
if(md5($password)!=$record['password'])
{
die("You provided an incorrect password. Please try again.");
}
}
mysql_close($con);
?>