0

Possible Duplicate:
What is the best “forgot my password” method?

After reading about different forgotten password request techniques, I have decided to go with sending a user a link by email where they can go to change their password. My question is what is the best way to do this? Here's my current method:

  1. Ask the user for their email
  2. Send them a link to a newpassword.php page with a randomly-generated long alphanumeric code as a parameter.
  3. hashing that code and storing it in a mysql table with the email address and timestamp
  4. when the user goes to the link, they're asked for their email again.
  5. search the table for that email. if the timestamp is over 24 hours, it's deleted and the user has to request another link.
  6. check that the code matches. if so, let user reset password.
  7. change the password in the users table and send another email to confirm it has been changed.

I'm new to website security, but I haven't found many examples of algorithms for having a user reset a forgotten password (except for simply creating a new one and sending it to them, which seems rather weak to me). Are there any security flaws in my approach? Anyone know any good guides I can look into? Thanks in advance!

Community
  • 1
  • 1
Chris
  • 3,369
  • 6
  • 32
  • 45

1 Answers1

0

I'll refer you to a very similar post. My answer was accepted there and I do not really want to rewrite the whole thing...

Looking for a some good options to send users reset password emails

Community
  • 1
  • 1
Kai Qing
  • 18,359
  • 5
  • 34
  • 56