Clicky

Interacting with MySQL what are the steps to send a forgot your password email. How does password get hidden and changed

asked 12/12/2011 02:57

rgb192's gravatar image

rgb192 ♦♦


4 Answers:
1. Always store encrypted passwords. Typical is MD5(). Note: PHP MD5 gives different results than MySQL MD5. Pick one and stick with it.

2. Have a field called reset_random. Default this field to zero for everyone.

3. When someone requests a password reset, make up a random number and store it in this field. Then send them an email (ONLY send to previously stored email addresses). This email will have a web link www.mysite.com/password_reset?email=me@gmail.com&code=12345 where 12345 is that random number. You could use the customer id instead of the email. I also set a date/time so the code is only good for a few hours.

4. When they visit that page verify first that the code is not zero, everyone is set to zero so this have to be excluded. Then verify that the customer record has that random number in their data and if you used the date/time, that it hasn't been too long since you sent out the email.

5. If all this looks ok, present them with a html form to enter a new password, confirm new password. Also in this form have hidden fields for customer id and that random number.

6. After entering the password and confirm password. You're ready to update the customer record. Verify that the hidden field still contains the correct random number (if you really wanted you could use a math function on the emailed random number when you place it in the html form)

7. If all seems correct encode the new password and zero the random number field. If the hidden fields do not match, then zero the random number to prevent a flood of guesses from resetting the password.

Hope this gets you started.

Michael
link

answered

Michael701's gravatar image

Michael701

The pseudocode:

1. first of all you have a user who has forgotten a password (with a old pass hashed with md5 or sha1 in the database)
2. you create a form where a user enters his email address to send a new generated password
3. you generate a password hashed with one of the above algorithms and replace the old pass in the database with a new one
4. you send an email with a link to click to reset password - www.yoursite.com/index.php?user=somebody&newpass=HASHED_NEW_ONE
5. you check on the page if the new pass from the $_GET array is exactly the same as the one in the database for the $_GET[user]
6. voila, only the user who can get the email can click the link to reset password

Additionally - you can include the result page of the password reset with the form to enter new password. Hope I'm clear - if not - feel free to ask more.
link

answered 2011-12-12 at 11:49:22

Roads_Roads's gravatar image

Roads_Roads

MD5 has been proven insecure. I'd suggest picking a stronger algorithm.
link

answered 2011-12-12 at 11:51:52

kaufmed's gravatar image

kaufmed

thanks
link

answered 2011-12-12 at 21:23:38

rgb192's gravatar image

rgb192

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×191

Asked: 12/12/2011 02:57

Seen: 350 times

Last updated: 12/16/2011 05:46