Php implements crypt encryption for user registration passwords, and users register crypt

Source: Internet
Author: User
Tags crypt

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.

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.