I have an admin area where the owner can set a username and password for the client. Those details are automatically sent to the client in an email.
I am using the code below, so that the first password entry is encrypted and put in the database, and the second exactly the same password entry is used to confirm the password in the email back to the client.
So the password is encrypted in the database, and so I then go to the log in screen for the clients and wondered if i need use md5 in the password field there to read the encrypted password in the database.
My code is below:
Admin are:
// Connect to server and select database.
mysql_connect("$host", "$user", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=md5($_POST['email']);
//$email=$_POST['email'];
$email2=$_POST['email2'];
// Insert data into mysql
$sql="UPDATE Register SET Username='$lastname', Password='$email' WHERE Email='$name'";
$result=mysql_query($sql);
//$result=mysql_query($sql) or die('mysql error : ' . mysql_error() . ' in query: ' . $sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "This update has been successful. Check the details below before moving on.";
echo "<BR>";
echo "<BR>";
echo "Username is: $lastname";
echo "<BR>";
echo "<BR>";
echo "Password is: $email2";
echo "<BR>";
echo "<BR>";
echo "<a href='http://www.tourcheck.co.uk'>Click here to return to the main page</a>";
echo "<BR>";
echo "<BR>";
echo "<a href='insert.php'>Click here to edit another account.</a>";
$to = $name;
$subject = "TourCheck: Your Username & Password";
$body = "Hello,\
\
Below are the user details for you to log into the TourCheck website.\
\
Please keep these details safe:\
\
Username: $lastname\
\
Password: $email2\
\
If you have any questions please contact tourcheck@checksafetyfirst.com\
\
www.tourcheck.co.uk";
if (mail($to, $subject, $body)) {
echo("<p>Email successfully sent to: $name</p>");
} else {
echo("<p>Email delivery failed...</p>");
}
}
else {
//echo "ERROR";
echo $sql;
//echo $sql2;
//echo $name;
//echo $lastname;
//echo $email;
}
// close connection
mysql_close();
?>
Log In screen wit commented out md5 encryption code that I have been trying.
// Connect to server and select databse.
mysql_connect("$host", "$user", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
// encrypt password
//$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
//$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$encrypted_mypassword'";
//$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file ".php"
session_register("myusername");
session_register("mypassword");
//header("location:.php");
header("location:/tourCheck/.php");
}
else { ?>
Basically when i try to log into the system using the username and password I used, it doesnt work.
Can anybody advise