


PHP method to implement crypt encryption of user registration password
This article mainly introduces php to implement crypt encryption of user registration passwords in detail. It has certain reference value. Interested friends can refer to it
1. Code
1, conn.php
<?php $conn = mysql_connect("localhost", "root", "111") or die("连接数据库服务器失败!".mysql_error()); //连接MySQL服务器 mysql_select_db("db_database21",$conn); //选择数据库db_database21 mysql_query("set names utf8"); //设置数据库编码格式utf8 ?>
2, index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>用户注册</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } --> </style></head> <body> <form id="form1" name="form1" method="post" action="index_ok.php"> <fieldset style="width:500px"><legend style="font-size:16px">用户注册</legend><table width="300" border="0" align="center"> <tr> <td width="77" align="right">用户名:</td> <td width="213"><input name="user" type="text" id="user" size="24" /></td> </tr> <tr> <td align="right">密码:</td> <td><input name="pwd" type="password" id="pwd" size="25" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="sub" value="注册" /> <input type="reset" name="res" value="重置" /></td> </tr> </table></fieldset> </form> </body> </html>
3. index_ok.php
<?php header("content-type:text/html;charset=utf-8"); //加载头信息 include("conn/conn.php");//包含数据库连接文件 if(trim($_POST['user'])!= "" and trim($_POST['pwd'])!= ""){//判断输入是否为空 $pwd = crypt($_POST['pwd'],"key");//对输入的密码进行crypt加密 $sql = "insert into tb_user(username,password)values('".$_POST[user]."','". $pwd."')";//定义sql语句 $result = mysql_query($sql,$conn);//执行sql语句 if($result){ echo "<font color='red'>注册成功。</font>";//如果结果为真提示注册成功 }else{ echo "<font color='green'>注册失败!</font>";//否则提示注册失败 } }else{ echo "请认真填写用户名和密码!";//提示输入用户名和密码 } ?>
2. Running results
After successful registration, the database displays as follows:
Related recommendations:
php user registration information usage Regular expression verification sample code
php password encryption example using crypt when registering
PHP user Registration Email activation function
The above is the detailed content of PHP method to implement crypt encryption of user registration password. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

The top ten cryptocurrency trading platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Kraken, 5. Huobi, 6. Coinbase, 7. KuCoin, 8. Crypto.com, 9. Bitfinex, 10. Gemini. Security, liquidity, handling fees, currency selection, user interface and customer support should be considered when choosing a platform.
