bo0
04-10-2005, 11:03 AM
I have created the following forgot password script, it works, but I really think it needs making more secure and generally stronger. Any ideas?
<?
// TouringNet - Forgot password
if (isset($_POST['request'])) {
@extract($_POST);
$query="SELECT * FROM users WHERE email='$Email' LIMIT 1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$pass = generate_password();
$md5pw = md5($pass);
if(mysql_num_rows($result) == 0)
{
echo "<strong>There is no user registered with that email address, please go back and try again!</strong></span>";
} else {
$id=mysql_result($result,"id");
$query = "UPDATE users SET password='$md5pw' WHERE id='$id' LIMIT 1";
mysql_query($query) or die("Could not insert data because ".mysql_error());
$subject=("TouringNet Password");
$text=("Your new TouringNet password is $pass\n To login please goto http://touringnet.co.uk/chris\n\n\n If you did not request a password change please ignore this email.");
$name=("TouringNet");
mail($Email,$subject,$text,"From: $name <$Email>");
echo("<body onLoad=\"MM_popupMsg('Your new password has been sent to the email you signed upto TouringNet with. Press Ok to return to our homepage.')\">");
echo("<meta http-equiv=\"refresh\" content=\"0;URL=./?q=news\">");
}
} else {
echo("<table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >");
echo(" <tr>");
echo(" <td height=\"19\" colspan=\"2\" valign=\"top\" class=\"unnamed1\"><span class=\"style3\">Forgot password form</span></td>");
echo(" </tr>");
echo(" <tr>");
echo(" <td width=\"6\" height=\"4\"></td>");
echo(" <td width=\"518\"></td>");
echo(" </tr>");
echo(" <tr>");
echo(" <td height=\"57\"></td>");
echo(" <td valign=\"top\"><span class=\"style7\">");
echo("To have your password emailed to your registered TouringNet email address please use the following form:<br>");
echo("<br>");
echo("<form name=\"forgotpass\" method=\"post\" action=\"\">");
echo(" <p>");
echo(" E-Mail address: ");
echo(" <input name=\"Email\" class=\"forms\" type=\"text\" id=\"Email\">");
echo(" <input type=\"submit\" class=\"forms\" name=\"request\" value=\"Submit\">");
echo(" </p>");
echo(" </form></span></td>");
echo(" </tr>");
echo(" </table>");
}
?>
<?
// TouringNet - Forgot password
if (isset($_POST['request'])) {
@extract($_POST);
$query="SELECT * FROM users WHERE email='$Email' LIMIT 1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$pass = generate_password();
$md5pw = md5($pass);
if(mysql_num_rows($result) == 0)
{
echo "<strong>There is no user registered with that email address, please go back and try again!</strong></span>";
} else {
$id=mysql_result($result,"id");
$query = "UPDATE users SET password='$md5pw' WHERE id='$id' LIMIT 1";
mysql_query($query) or die("Could not insert data because ".mysql_error());
$subject=("TouringNet Password");
$text=("Your new TouringNet password is $pass\n To login please goto http://touringnet.co.uk/chris\n\n\n If you did not request a password change please ignore this email.");
$name=("TouringNet");
mail($Email,$subject,$text,"From: $name <$Email>");
echo("<body onLoad=\"MM_popupMsg('Your new password has been sent to the email you signed upto TouringNet with. Press Ok to return to our homepage.')\">");
echo("<meta http-equiv=\"refresh\" content=\"0;URL=./?q=news\">");
}
} else {
echo("<table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >");
echo(" <tr>");
echo(" <td height=\"19\" colspan=\"2\" valign=\"top\" class=\"unnamed1\"><span class=\"style3\">Forgot password form</span></td>");
echo(" </tr>");
echo(" <tr>");
echo(" <td width=\"6\" height=\"4\"></td>");
echo(" <td width=\"518\"></td>");
echo(" </tr>");
echo(" <tr>");
echo(" <td height=\"57\"></td>");
echo(" <td valign=\"top\"><span class=\"style7\">");
echo("To have your password emailed to your registered TouringNet email address please use the following form:<br>");
echo("<br>");
echo("<form name=\"forgotpass\" method=\"post\" action=\"\">");
echo(" <p>");
echo(" E-Mail address: ");
echo(" <input name=\"Email\" class=\"forms\" type=\"text\" id=\"Email\">");
echo(" <input type=\"submit\" class=\"forms\" name=\"request\" value=\"Submit\">");
echo(" </p>");
echo(" </form></span></td>");
echo(" </tr>");
echo(" </table>");
}
?>