PHP:How to send the original password to the user when he clicks forgot password which is encrypted by using md5?

后端 未结 5 1698
野的像风
野的像风 2020-11-29 09:04

I am using md5 to encrypt the passwords in my project.

When user clicks on forgot password and submits his email,I have to send His password to him.

But the

5条回答
  •  鱼传尺愫
    2020-11-29 09:18

    Hashes are not designed to be decrypted, which is why they're often referred to as "one-way hashes" instead of just hashes.

    Instead, either...

    1. Generate a new password, hash that, store the new password hash in place of the old one, and email the newly generated password to the user.

    2. Generate a new password, hash it, store it in a field for temporary passwords, and then when the user logs in with that password, prompt them to enter a permanent new password.

    3. Generate a nonce, store it in a field for the nonce, and email the user a link with that nonce which will give them access to a page to enter a new password.

    The third option is probably the best all around, since it doesn't leave an actual password (temporary or not) in plain view to someone reading the user's email, and since it utilizes a nonce, once it has been used it can't be used again by a malicious user.

    The reason hashing is used for passwords is specifically to prevent them from being stored in a form where a malicious user could determine the password simply by looking at the database.

    Edit:

    "So i have to show the original password to Admin."

    If you are hashing the password, this is not possible. In general, it is actually a bad idea to allow administrators to see users' passwords, because a large percentage of users tend to utilize the same password for multiple things, and the administrator of one thing (say, a company network) is probably not the administrator of many other things (say, a user's online banking system).

    MD5 is not an encryption algorithm, it is a hashing algorithm. The two are not the same; encryption is designed to be reversible (hence the complementary term "decryption"), whereas hashing is designed to be one-way only.

提交回复
热议问题