I have a script when the users lose their password they enter there email address and then a new one is generated and sent to them by email. I have the code below and at the minute I enter the email address and nothing happens.
The variable info is
page forgotpass.php
field in db called "password"
email field is called "email"
"password" field is number 17"
However I don't think it is getting this far because I enter a email address and it just disappears I do not get any error messages.
I have tried to debug (using echo hello) and all worked fine until I put it after this line return $password;
I have left the echo in to show. Even if I put in "ffvfdhdav" it doesn't bring the error message saying email not found just dissappears again obv not getting this far, any ideas?
<?php
session_start();
include("data/data.php");
$conn = mysql_connect($servername, $user, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($user, $conn);
function generatePassword ($length)
{
// start with a blank password
$password = "";
// define possible characters
$possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ";
// set up a counter
$i = 0;
// add random characters to $password until $length is reached
while ($i < $length) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
// done!
return $password;
//echo "hello";
}
//only run this code if submit button pressed
if ($_POST['action']=="Reset Password") {
//check that email address does exist in database before attempting to reset
$sql = "SELECT * FROM `sign_up` where email='".mysql_real_escape_string($_POST['emailaddress'])."'";
$result = mysql_query($sql);
//check there was a return if not show error
if ($result==FALSE) {
$err="Email address not found in database please enter the email address used on account creation";
} else { //if there was a return begin reset process.
generatePassword(8);//call password generation function number is password length to be generated
$updatesql = "UPDATE `sign_up` SET password='".md5($password)."' where email='".mysql_real_escape_string($_POST['emailaddress'])."'";
$result2 = mysql_query($updatesql);
if (!$result2) {
die('Invalid query: ' . mysql_error());
}
$msg = '';
$msg .= 'Password information for mysite.co.uk<br>';
$msg .= '<br>';
$msg .= 'Your new password is: '.$password.'<br>';
$emailaddress = $_POST['emailaddress'];//destination email address
$email = 'info@mysite.co.uk'; //Sets the senders mail address - you may want to change this
$mailheader = "From: $email\r\nContent-type: text/html\r\n";
mail($emailaddress, 'Your new password for gdg', $msg, $mailheader);//this sends the mail the bit in '' appears as the subject to the email and the body is $msg
$confirm = "Your Password has been updated in the database and emailed to the address registered with our system.";
}
}
?>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#DAE8FF">
<tr>
<form action="forgotpass.php" method="post" name="form1" id="form1">
<td height="172">
<table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bordercolor="#DAE8FF" bgcolor="#DAE8FF"><div align="center"><strong>Forgotten Password</strong></div></td>
</tr>
<?php if (strlen($err)>0) {?>
<tr>
<td colspan="3" bordercolor="#DAE8FF" bgcolor="#DAE8FF"><div align="center"><strong><font color="red"><?php echo $err;?></font></strong></div></td>
</tr>
<?php } ?>
<tr>
<td colspan="3" bordercolor="#DAE8FF" bgcolor="#DAE8FF">If you have forgotten your password simply fill in this form with the email address registered against your account. We will generate a new password and email it to you.</td>
</tr>
<tr>
<td width="78" bordercolor="#DAE8FF" bgcolor="#DAE8FF">Email Address</td>
<td width="6" bordercolor="#DAE8FF" bgcolor="#DAE8FF">:</td>
<td width="294" bordercolor="#DAE8FF" bgcolor="#DAE8FF"><input name="emailaddress" type="text" id="emailaddress" /></td>
</tr>
<tr>
<td bordercolor="#DAE8FF" bgcolor="#DAE8FF"> </td>
<td bordercolor="#DAE8FF" bgcolor="#DAE8FF"> </td>
<td bordercolor="#DAE8FF" bgcolor="#DAE8FF"><input type="submit" name="action" id="action" value="Reset Password" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table></p>