Forgot my Password feature

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jparsons
Forum Newbie
Posts: 2
Joined: Sun Mar 16, 2003 9:04 pm

Forgot my Password feature

Post by jparsons »

I am using Dreamweaver MX to build a PHP-based site. I have a login system in place. However, I would like to create a page that emails forgotten passwords to users. Any idea on where I might find code for this? I am somewhat novice with PHP, but good at adapting existing code.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Are you using a MySQL database?
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

How are you storing their password? Plaintext or encrypted? If it is encrypted then you really can not email it to them. Instead they should fill out a forgoten pw form and then have a random pw generated and emailed to them. Of course this is all if you are using a Database.
jparsons
Forum Newbie
Posts: 2
Joined: Sun Mar 16, 2003 9:04 pm

Post by jparsons »

Im using MySQL with non-encrypted passwords.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Well, for example you could use this code. I just made it so that they enter their email and it it'll send the password to the email they filled out:

Code: Select all

<?php
if($get == "password") {
$getpass = mysql_fetch_array(mysql_query("select password from users where email=''$email"));

$yourname = "Your Name";
$youremail = "you@yourdomain.com";
$subject = "Your lost password";
message = "Your lost password is $getpass[password]";

@mail($youremail, $subject, $message, "From: "$yourname"<$youremail>\r\nReply-To: $youremail\r\nX-Sender:$yourname using $youremail\r\nReturn-Path: $youremail");

echo "Your password has been sent to your email";
}
else {
?>
<form action="getpass.php" method="get">
<input type="hidden" name="get" value="password">
Email: <input type="text" name="email"> <input type="submit" value="Get My Password!">
</form>
<?php
}
?>
Hope that helps!
Post Reply