How can I encrypt my website registration and login password? -Php Tutorial

Source: Internet
Author: User
How can I encrypt my website registration and login password? I have read many articles in this regard on the Internet, all of which refer to the client password. when logging on, I will use md5 encryption to send it to the server, and then compare the server with the salt in the database and the encrypted password.

I don't understand. if this is the case

Assume that the user name of User A is abcd and the password is 123456. after md5 is encrypted, it is e10adc3949ba59abbe56e057f20f883e.
The hacker accidentally obtained the username abcd and password e10adc3949ba59abbe56e057f20f883e.

At this time, he does not need to know that the abcd password is 123456, and does not need to understand how e10adc3949ba59abbe56e057f20f883e is generated. he only needs to enter the user name: abcd, and then the password: e10adc3949ba59abbe56e057f20f883e to call the service and you can log on.

How can we avoid this situation?


Reply to discussion (solution)

How do hackers know the username abcd and ciphertext?

Client does not require encryption
You only need to follow the normal user name and password to log on.

Then, the server performs the md5 (md5 (password) + salt) operation on the password to generate the encrypted password. Salt is obtained from the database.
Compare with the encrypted password in the database.
If they are the same, the logon is successful. Otherwise, the logon fails.

The advantage of this approach is that even if the database is hacked, the user's plaintext password cannot be known.

The server password is so different.

If ($ row ['pwd'] = md5 ($ _ POST ['pwd']) {
//
}
Even if someone else knows the password after MD5, but comes to the server, it needs to be encrypted again, or encrypted multiple times and then compared.

Even if hackers hacked into your database, they obtained your member's username and encrypted password, because md5 encryption is basically irreversible, therefore, hackers cannot call the services you know to perform login operations.

However, one layer of md5 encryption is not very secure, and many websites provide md5 decryption. We recommend that you encrypt the md5 data multiple times or add your custom string and then encrypt it in md5 (md5 (user_passwd.your_defined_string )).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.