View Single Post
Old 08-05-2008, 01:32   #4 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,605
No, MD5 hashes it in the same manner that Sha1 does.

You can't retrieve a hashed password in an un-hashed form. Its a one way road.

What I have done is this:
1) When the user clicks 'forgot password', I bring them to a page where they input the email address they registered with. The user inputs their email address and then...
2) my script creates a random 20 character alphanumeric code. I hash this, and put it in the database. Then I append the unhashed version as a get variable to confirm.php, so it looks like this: confirm.php?number=askld23432kl324kl32jklj234 or something. I email this link to the account that the person registered under.
3) When the user clicks the link, they are taken to confirm.php. The first thing I do is grab $_GET['number'], hash it, and check to see if the hashed version is in the database. If it is, then I output an input into which the user has to again type their email address (this is an extra step to confirm that the person hasn't just started poking in random $_GET variables to see if they can find one that works).
4) After inputting their email address, I bring them to a page where I first check to see if that email address was correct. If it was, they enter their new password into a form and hit submit, and the script updates their password in the database with the new password.

That's the thing about passwords if they are done correctly - only the user ever knows what they are. They aren't visible when the user types it in (due to everything outputting as asterix's), and they are hashed before entry in the database, so even the administrator doesn't know the user's password. And in this way they can never be recovered, only overwritten.
__________________
This space for rent.

Dads Japan
Dudes Japan
  Reply With Quote