Yogiz Posted February 25, 2008 Share Posted February 25, 2008 Hi guys, Was wondering if someone could provide me with some guidance as I'm new to php on how to write a password reminder script. At the moment I have username (sha1) password and e-mail stored in mysql database, how do I extract the password from the database when it uses sha hash and e-mail it to the user? Thanks in advance. Yogiz Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 You don't. When the user says they lost a password, you generate a random, temporary password and email it to them. Any other way would be a completely pointless use of a hashing/encryption method. A random password could be generated like this: - Edited to change something I didn't like about the method I chose the first time. <?php function random_password($length=16) { $chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)); $string = ''; for ($i = 0; $i < $length; $i++) { $string .= $chars[array_rand($chars)]; } return $string; } ?> Quote Link to comment Share on other sites More sharing options...
Yogiz Posted February 26, 2008 Author Share Posted February 26, 2008 Great thanks for that. How do I upload the generated password to the database and then e-mail it to the user? Yogiz Quote Link to comment Share on other sites More sharing options...
unsider Posted February 26, 2008 Share Posted February 26, 2008 INSERT INTO // database Use mySQL commands to enter the generated pass into database, then retreive the info from DB, and design a little email script. Look for tutorials, you are trying to do some basic stuff, I actually believe I've seen some things you're looking for. If I find some, I'll letcha know. Quote Link to comment Share on other sites More sharing options...
Yogiz Posted February 26, 2008 Author Share Posted February 26, 2008 Could someone help in more detail? Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted February 26, 2008 Share Posted February 26, 2008 Same way you registered their password except a little different. Create a Reset Password page, have them enter their username or email and it verifies the email is there (SELECT * FROM table WHERE username = $username) or email then if its present you will run the function as a variable even $newpass=random_password(); posted above and UPDATE table SET password = '$newpass' WHERE username = '$username' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.