php实现用户注册密码的crypt加密

<?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 method="post" action="index_ok.php"> <fieldset><legend>用户注册</legend><table> <tr> <td>用户名:</td> <td><input type="text" size="24" /></td> </tr> <tr> <td>密码:</td> <td><input type="password" size="25" /></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" value="注册" /> <input type="reset" 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 "请认真填写用户名和密码!";//提示输入用户名和密码 } ?>

二、运行结果

注册成功后,数据库显示如下:

php实现用户注册密码的crypt加密

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1caf58cb17ca2b5a0a4fc78fa272ab6f.html