forgot password

Place to place any code snippets, completed games, or even uncompleted games for IR users to use.
Post Reply
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

forgot password

Post by dust1031 »

i just coded this and it worked. basically i used the same code for changepassword and my email activation code and changed some things

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 this sends the password link to change your password to the email that is attached to your username in the DB.

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>
";
 }

?>
now this is another form you type in your UserName Your password and repeat your password. Then it looks for your UserName that you typed in, in the DB and changes your password according to what you typed in on new password and repeat new password. and then u can log in with your new password.
Hope this code helped some of y'all
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: forgot password

Post by SpiritWebb »

Thanks for sharing!!
Image

Image
rRussellr
Posts: 14
Joined: Sun Oct 30, 2011 7:44 pm

Re: forgot password

Post by rRussellr »

For a bit of extra security I'd be tempted to create a random string that's stored in the member table rather than the username as you could then just change other members passwords..

My preferred method is to ask for an email address check if ou have a user with that email then create that random string and include all that in the email you send with that string attached. ( http://compengines.co.uk/index.php?page=forgot_pass )
Post Reply

Return to “Code Sharing”