Hi,
I am trying to write a password reset script that will generate a random password, update the table in the database (adding sha1 to the randomly generated password) and then email the randomly generated password (before sha1 hashing) to the user so they can login and then change it to something they will remember.
My problem is that it keeps erroring out and won't update the record. My guess is that there is some syntax that is missing/wrong, but I've been beating my head against this and can't seem to get it to work. The code is below.
Please help!
Thanks in advance,
kaiman
// connects to server and selects database.
include ("dbconnect.inc.php");
// table name
$tbl_name="registered_members";
// generates random password
// include ("randompass.inc.php");
// generates random password with the following letters and numbers
function randomPass($length) {
$letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
$newpass = "";
for($i = 0; $i < $length; $i++) {
$newpass .= $letters[rand(0,61)];
}
return $newpass;
}
// returns random 8 character password
$pass = randomPass(;
// protects against mysql injection
function cleanString($string){
htmlentities(mysql_real_escape_string($string));
return $string;
}
// values sent from form
$username = cleanString($_POST['username']);
$email = cleanString($_POST['email']);
// check for empty fields
if (empty($username) || empty($email)) {
echo "Please Complete All Form Fields";
exit ;
}
//account check
$sql="SELECT count(*) FROM $tbl_name WHERE username='$username' and email='$email'";
$result=mysql_query($sql);
$num = mysql_result($result,0);
//check to see if username and email exists or not.
if($num < 1){
echo "That Username or Email Address Does Not Match Our Records. Please Provide A Valid Username and Email Address.";
exit();
}
// if email is found update data in database
$sql="UPDATE $tbl_name SET pass='" . sha1($pass) . "' WHERE username='$username' and email = '$email'";
$result=mysql_query($sql);
// if data is successfully changed in database, send email to user
if($result){
// send e-mail to
code, blah, blah, blah