echo file_get_contents('template/header.html'); ?>
require('includes/db.php');
require('includes/settings.php');
displayTitle("Forgotten your Username or Password?");
$email = $_POST['email'];
//The complicated Validation
$error = false;
if (isset($_POST["submit"])) {
if (!isset($email) or $email == "" or $email == " ") {
echo "Error: You must specify an email!
";
$error = true;
}
if (!$error) {
$aQuery = mysql_query ("SELECT * FROM stagdata_user where UPPER(email)='".strtoupper($email)."'");
if ($row = mysql_fetch_array($aQuery)) {
$username = $row['username'];
} else {
echo "Error: Email not valid!
";
$error = true;
}
}
}
if (isset($_POST["submit"]) and !$error) {
$newPassword = generatePassword();
$aQuery = mysql_query ("UPDATE stagdata_user set password='".md5($newPassword)."' where UPPER(email)='".strtoupper($email)."'");
$recipient = $email;
$mail_body = "Your username is:-
".$username."
Your new password is:-
".$newPassword;
$subject = $system_from_subject_prefix." new password requested";
$header = "From: ".$system_from_name." <".$system_from_email.">\r\n".'Content-Type: text/html; charset="iso-8859-1"\r\n';
mail($recipient, $subject, $mail_body, $header);
echo "Successfully sent new password to $email!";
} else {
?>
}
function generatePassword($length=6,$level=2){
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
$validchars[1] = "0123456789abcdfghjkmnpqrstvwxyz";
$validchars[2] = "0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$validchars[3] = "0123456789_!@#$%&*()-=+/abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!@#$%&*()-=+/";
$password = "";
$counter = 0;
while ($counter < $length) {
$actChar = substr($validchars[$level], rand(0, strlen($validchars[$level])-1), 1);
// All character must be different
if (!strstr($password, $actChar)) {
$password .= $actChar;
$counter++;
}
}
return $password;
}
?>
echo file_get_contents('template/footer.html'); ?>