Home > Backend Development > PHP Tutorial > How to encrypt password in php? Introduction to MD5() function encryption

How to encrypt password in php? Introduction to MD5() function encryption

青灯夜游
Release: 2023-04-04 08:44:01
Original
6838 people have browsed it

How to encrypt password in php? I believe that many friends who have just come into contact with php will have such questions. This chapter will introduce to you how PHP encrypts passwords and introduces the MD5() function encryption. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

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);
Copy after login

string: Specifies the string to be calculated and the required parameters.

raw: Specifies hexadecimal or binary output format, you can choose to set the parameters, there are the following two output formats:
TRUE - raw 16-character binary format;
FALSE - 32 character hexadecimal number, this is the default value.

md5() encryption is an irreversible encryption method. Let's look at an example:

$password = '123456';
echo md5($password);
Copy after login

This will encrypt the password "123456" into "e10adc3949ba59abbe56e057f20f883e", which is not good was cracked.

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>
Copy after login

Running results:

How to encrypt password in php? Introduction to MD5() function encryption

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 in php? Introduction to MD5() function encryption. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template