5

I have database entry for password in md5 format, but when user uses the "Forgot password" then how can i give him/her the desired password?

OM The Eternity
  • 15,694
  • 44
  • 120
  • 182
  • 1
    Oblig. nitpick: MD5 function is *hashing* - information is lost from the result, the original data is not recoverable. With *encryption* OTOH, the original data can be fully recovered with the correct key. – Piskvor left the building Dec 13 '10 at 11:49
  • possible duplicate of [Is it possible to decrypt md5 hashes?](http://stackoverflow.com/questions/1240852/is-it-possible-to-decrypt-md5-hashes) – Mechanical snail Jan 07 '13 at 23:26

5 Answers5

12

You can't do that from an MD5 hash; nor should you be able to. Password recovery ought to be intractable.

The usual process is to send a password-reset token (URL) to their email address so that the user can choose a new password.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
3

You can't - MD5 is simply a "one way" hash - not a means of encrypting data that can subsequently be de-crypted.

As such, the general idea is to:

  1. Send the user an email to their registered address with a reset link in it. (To prove they actually own the address.) The reset link should contain a hash based on some aspect of their specific user data so it can't be easily guessed, etc. (e.g.: Account creation time.)

  2. When the user clicks the link they land on a password reset page that checks the above hash, generates a new password (ideally a mix of upper/lower and some numeric characters, although I always tend to omit character such as '0', 'o', 'O', etc. for the sake of clarity) and then sends the user the new password in an email, advising them that they should change this password as soon as possible.

The user can then log-in and access the site as per usual.

John Parker
  • 54,048
  • 11
  • 129
  • 129
  • I would just skip the second email sending new password. Let the user change the password directly from that link. – Danosaure Dec 13 '10 at 16:55
2

You can't do it without putting the password in the database, which is undesirable, but you can generate him/her a new password and send it to them. Or a link where they can reset their password.

terminus
  • 13,745
  • 8
  • 34
  • 37
2

you have to send a new password to the user and then set into the database also. otherwise the original password may not recover.

Thanks.

Chandresh M
  • 3,808
  • 1
  • 24
  • 48
1

You got a 1/100 chance of recovering that password (dictionary method) given the length of the password. I won't recommend it.

It's better to generate a new random password, and send it to the user's email.

Ruel
  • 15,438
  • 7
  • 38
  • 49
  • Much less than 1/100, actually - that's the whole point of hashing: simple and fast one way (data to hash), complicated and very slow (as in "almost impossible when done right") in the other direction (hash to data). – Piskvor left the building Dec 13 '10 at 11:52
  • @Piskvor actually that's just my estimation. :P it would depend on the dictionary used. – Ruel Dec 13 '10 at 11:53
  • If you are getting a 1/100 recovery rate. You have a terribly insecure system. In fact, you can test your own system for recovery rates using the various md5 de/encoders out there. Shoot for 0% recovery. http://www.md5decrypter.com/ – DampeS8N Dec 13 '10 at 12:37