Home > Article > Backend Development > How to encrypt password with md5 in php
How to encrypt password in php? I believe that many friends who have just come into contact with php will have such questions. Let me introduce to you how PHP encrypts passwords and introduces the MD5() function encryption.
md5() function introduction
md5() function calculates the MD5 hash of a string, using RSA data security, including the MD5 message digest algorithm.
The MD5 algorithm is primarily designed for digital signature applications; in this digital signature application, larger files will be encrypted (where the encryption process is performed under a cryptographic system [such as: RSA ] is done by setting the private key under the public key) before compressing in a secure manner.
md5() function syntax
md5(string,raw);
string: Specifies the string to be calculated and the required parameters.
raw: Specifies the hexadecimal or binary output format, you can choose to set the parameters, there are the following two output formats:
TRUE - original 16-character binary format;
FALSE - 32 character hexadecimal number, this is the default value.
Related recommendations: "php tutorial"
md5() encryption is an irreversible encryption method. Let's take a look at an example:
$password = '123456'; echo md5($password);
This will encrypt the password "123456" into "e10adc3949ba59abbe56e057f20f883e", which will be difficult to crack.
md5() function example
Let’s take a look at an example of how PHP uses md5() encryption to verify information
<!DOCTYPE html> <html> <body><?php $str = "Hello"; echo md5($str);//输出加密后的密码 if (md5($str) == "8b1a9953c4611296a827abf8c47804d7")//加密后的密码和已有的密码进行比对,相同就输出Hello world! { echo "<br>Hello world!"; exit; } ?> </body> </html>
Running results:
We can use it together with the database to call the user name and password in the database for comparison and verification to check the information for user login and other operations.
The above is the detailed content of How to encrypt password with md5 in php. For more information, please follow other related articles on the PHP Chinese website!