Php implements crypt encryption for user registration passwords, and users register crypt
The example in this article shares the encryption of the php user registration password for your reference. The details are as follows:
I. Code
1. conn. php
<? Php $ conn = mysql_connect ("localhost", "root", "111") or die ("failed to connect to the database server! ". Mysql_error (); // connect to MySQL Server mysql_select_db ("db_database21", $ conn); // select database db_database21 mysql_query ("set names utf8 "); // set the database encoding format utf8?>
2. index. php
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. index_ OK .php
<? Php header ("content-type: text/html; charset = UTF-8"); // load header information include ("conn/conn. php "); // contains the database connection file if (trim ($ _ POST ['user'])! = "" And trim ($ _ POST ['pwd'])! = "") {// Determines whether the input is null $ pwd = crypt ($ _ POST ['pwd'], "key "); // encrypt the entered password with crypt $ SQL = "insert into tb_user (username, password) values ('". $ _ POST [user]. "','". $ pwd. "')"; // define the SQL statement $ result = mysql_query ($ SQL, $ conn); // execute the SQL statement if ($ result) {echo "<font color = 'red'> Registration successful. </Font> "; // if the result is true, the registration is successful.} else {echo" <font color = 'green'> Registration failed! </Font> "; // otherwise, a message indicating an error occurred.} Please enter your username and password carefully! "; // Prompt to enter the user name and password}?>
Ii. Running result
After successful registration, the database displays the following:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.