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

yipeiwu_com6年前PHP代码库

本文实例为大家分享了php用户注册密码的加密,供大家参考,具体内容如下

一、代码

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 "请认真填写用户名和密码!";//提示输入用户名和密码 
  } 
?>  

二、运行结果

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【宜配屋www.yipeiwu.com】。

相关文章

简单谈谈PHP中strlen 函数

strlen函数说明。 int strlen ( string $string ) 在这篇文章,我们可以知道strlen函数是通过Zend Engine定义的。函数的定义可以在这里查看...

php微信支付之APP支付方法

本文实例讲述了微信开放平台移动应用集成微信支付功能。分享给大家供大家参考。具体分析如下: WechatAppPay文件代码如下: 复制代码 代码如下: <?php name...

php字符串替换函数substr_replace()用法实例

本文实例讲述了php字符串替换函数substr_replace()用法。分享给大家供大家参考。具体分析如下: substr_replace用于在指定字符串中替换指定位置的子字符串 &...

洪恩在线成语词典小偷程序php版

主要函数是file_get_contents,主程序分两段,跟我一起看过来吧(凡人博客原创代码,转载请注明)。 复制代码 代码如下: function escape($str){ pre...

完美解决令人抓狂的zend studio 7代码提示(content Assist)速度慢的问题

完美解决令人抓狂的zend studio 7代码提示(content Assist)速度慢的问题

最近用zend studio7.2 遇到个问题,就是打开内容很多的php页面(>500行)时,编辑保存速度奇慢。根据网络上google到的资料 ,更改了content Assist...