Example code for using MD5 functions in PHP-php Tutorial

Source: Internet
Author: User
The MD5 function in PHP uses the instance code. Generally, a website that provides member registration must collect the user's password. how to save the user password is a problem. We certainly cannot store passwords in plain text. generally, a website that provides member registration must collect user passwords. how to save user passwords 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:

 



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.

The above is the content of the instance code used by the MD5 function in PHP. For more information, see PHP Chinese network (www.php1.cn )!

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.