first make a link on your login called forgotpassword and make it go to forgotpassword.php, and put this code in
Code: Select all
<?php
if( isset($_POST['submit']) )
{
$email = $_POST['email'];
$name = $_POST['name'];
$server = "localhost";
$headers = "From:DoNotReply@EpicWorlds.com";
$subject = "Forgot Password";
$to = $email;
$body = ("Hello, you requested your password to be sent to your email,Click on the link below to change your password:
http://localhost/tutorial/changepassword1.php?name='$name';");
mail($to, $subject, $body,$headers);
}
echo ("Click on the link in your email to change your password.");
{
echo "
<form action='forgotpassword.php' method='POST'>
Your UserName:<input type='text' name='name'><br>
Your Email Address:<input type='text' name='email'><br>
<input type='submit' value='Send Password' name='submit'>
";
}
?>
now make another php file called changepassword1.php, and put this code in
Code: Select all
<?php
include 'connect.php';
?>
<?php
if( isset($_POST['submit']) )
{
$name = ($_POST['name']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
$queryget = mysql_query("SELECT password from players where name='$name'") or die("Could not get password field");
$row = mysql_fetch_assoc($queryget);
if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("
UPDATE players SET PASSWORD='$newpassword' WHERE name='$name'");
die("Your password has been changed <a href='login.php'>Login</a>");
}
else
die("The new passwords don't match!");
}
else
{
echo "
<form action='changepassword1.php' method='POST'>
UserName: <input type='text' name='name'><br>
New Password: <input type='password' name='newpassword'><br>
Repeat New Password: <input type='password' name='repeatnewpassword'><br>
<input type='submit' name='submit' value='Change Password'>
</form>
<a href='index.php'>Go Back<a>
";
}
?>
Hope this code helped some of y'all