Use the instance code for the MD5 function in PHP

Source: Internet
Author: User
PHP has a variety of functions, among which the MD5 encryption function is one. Http://www.cenusblog.com "> in general, a website that provides member registration must collect the user password, how to save the user password is a problem. Of course, we cannot store passwords in plain text in the database, because in this case, the general administrator can view the user password, which is obviously quite dangerous for the user.

So how can we solve this problem? we can adopt such a strategy.

First, we will introduce how to use the MD5 function in PHP:

The code is as follows:


$ Pswd1 = md5 ("cenusdesign ");
Echo $ pswd1; // The running result is fc60ec37d1c08d5b0fb67a8cd934d5ba.

$ Pswd2 = md5 ("Cenusdesign ");
Echo $ pswd2; // The running result is 067577d9fc0000c80538c81d6f02bd293.
?>



Obviously, after md5 encryption, the original "cenusdesign" is converted into a 32-bit string, and even if the case of a letter changes, this string will undergo a huge change.

Cenus Design recommends that you first convert the password to MD5 upon registration, and then convert the encrypted database. When a user logs in, the password is first converted to MD5, and then compared with the MD5 encrypted strings in the database. In this way, the password comparison can be completed without knowing the user's exact password.

By Sunec
Original: http://www.cenusblog.com "target = _ blank> Cenus Blog
Copyright. The author and original source and this statement must be indicated in the form of links during reprinting.

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.