PHP User Registration encrypts the password using crypt

Source: Internet
Author: User
Tags crypt
This article is mainly for everyone to introduce the PHP implementation of user registration password crypt encryption, with a certain reference value, interested in small partners can refer to

This example for everyone to share the PHP user Registration password encryption, for your reference, the specific content as follows

One, the code

1, conn.php

<?php   $conn = mysql_connect ("localhost", "root", "111") or Die ("Connection to database server failed!") ". Mysql_error ()); Connect 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 database connection file   if (Trim ($_post[' user '])! = "" and Trim ($_post[' pwd '])! = "") {//To determine if the input is empty     $pwd = crypt ($_post[' pwd '], "key");// Crypt encryption for the entered password     $sql = "INSERT into Tb_user (Username,password) VALUES ('". $_post[user]. "', '". $pwd. "')"; /define SQL statement     $result = mysql_query ($sql, $conn);//Execute SQL statement     if ($result) {       echo "<font color= ' Red ' > registered successfully. </font> ";//If the result is true prompt registration successful     }else{       echo" <font color= ' green ' > Registration failed!</font> ";//otherwise prompt registration failed     }   } else{     echo "Please fill in the user name and password carefully!" ";//Prompt for user name and password   }?>

Ii. Results of operation

After successful registration, the database appears as follows:

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.