kproc
04-19-2006, 09:03 PM
below is code that I', trying to use to set a new password for users, I have a test user setup and I tried to change the password but it always says "No records found matching your email address". I know that I'm typing the correct email because I', copying it from the email forwarded on registration
I thought is its because its looking in the incorrect column for the email address, any ideas
thank you
<html>
<head>
<title>Lost Password</title>
</head>
<body>
<?
include 'db.php';
switch($_POST['recover']){
default:
include 'lost_pw.php';
break;
case "recover":
recover_pw($_POST['email_address']);
break;
echo($_POST['email_address']);
}
function recover_pw($email_address){
if(!$email_address){
echo "You forgot to enter your Email address<br />;
include 'lost_pw.php';
exit();
}
// quick check to see if record exists
$sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo "No records found matching your email address<br />";
include 'lost_pw.php';
exit();
}
// Everything looks ok, generate password, update it and send it!
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("UPDATE users SET password='$db_password'
WHERE email_address='$email_address'");
$subject = "Your Password at MyWebsite!";
$message = "Hi, we have reset your password.
New Password: $random_password
http://www.tomorrownextweek.com/login.php
Thanks!
TomorrowNextWeek.com
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: tomorrownextweek <webmaster@tomorrownextweek.com>\n
X-Mailer: PHP/" . phpversion());
echo "Your password has been sent! Please check your email!<br />";
include 'login.php';
}
?>
</body>
</html>
I thought is its because its looking in the incorrect column for the email address, any ideas
thank you
<html>
<head>
<title>Lost Password</title>
</head>
<body>
<?
include 'db.php';
switch($_POST['recover']){
default:
include 'lost_pw.php';
break;
case "recover":
recover_pw($_POST['email_address']);
break;
echo($_POST['email_address']);
}
function recover_pw($email_address){
if(!$email_address){
echo "You forgot to enter your Email address<br />;
include 'lost_pw.php';
exit();
}
// quick check to see if record exists
$sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo "No records found matching your email address<br />";
include 'lost_pw.php';
exit();
}
// Everything looks ok, generate password, update it and send it!
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("UPDATE users SET password='$db_password'
WHERE email_address='$email_address'");
$subject = "Your Password at MyWebsite!";
$message = "Hi, we have reset your password.
New Password: $random_password
http://www.tomorrownextweek.com/login.php
Thanks!
TomorrowNextWeek.com
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: tomorrownextweek <webmaster@tomorrownextweek.com>\n
X-Mailer: PHP/" . phpversion());
echo "Your password has been sent! Please check your email!<br />";
include 'login.php';
}
?>
</body>
</html>