Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP dehashing the password

One must store the hashed password in the database for security reasons.

If a user does not remember their account password, how can they retrieve it back? I can only share their hashed password at this stage, which is useless to them.

Can you recover the password if it is hashed by md5, sha1 with additional salt?

like image 483
Suraj Avatar asked Sep 01 '10 06:09

Suraj


3 Answers

There is but one simple answer: You cannot.

Well, theoretically you could, but it could take many years per password if they are long enough. After all, that is the point of hashing passwords in the first place: to make the data effectively useless to an attacker (or at least protect the user's plaintext password, which is sensitive data.)

Just have the site send a "change your password" email containing a link to a page where that user can change his/her password. This is how most professional sites handle this dilemma.

like image 54
hb2pencil Avatar answered Nov 15 '22 10:11

hb2pencil


This is meant to be intractable. Thus, you usually have to provide some way of resetting it. Sending a special link to the user's email is common, though it reduces your security to that of the email account.

See Forgot Password: what is the best method of implementing a forgot password function? .

like image 24
Matthew Flaschen Avatar answered Nov 15 '22 11:11

Matthew Flaschen


The security of hashing instead of encrypting the password is that you cannot reverse a hash. If you could unhash the password and give the user their plain text password, then any hacker can reverse the hashed password you use for registration and sign in and "dehash" it to get the user's password.
This is a feature, not a bug.

like image 28
chustar Avatar answered Nov 15 '22 11:11

chustar