php使用crypt()函数进行加密


Posted in PHP onJune 08, 2017

一、代码

<?php 
 $str = '应用crypt()函数进行单向加密!';     //声明字符串变量$str 
 echo '加密前$str的值为:'.$str; 
 $crypttostr = crypt($str);      //对变量$str加密 
 echo '<p>加密后$str的值为:'.$crypttostr;  //输出加密后的变量 
?>

二、运行结果

参数不带salt,每次加密得出的密文都不一样。
加密前$str的值为:应用crypt()函数进行单向加密!
加密后$str的值为:$1$Re4.Gg4.$D.yd00xX0fFfIfp6KrKGN0

三、代码

<!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=gb2312" /> 
<title>使用crypt函数进行数据验证</title> 
<style type="text/css"> 
<!-- 
body,td,th { 
 font-size: 12px; 
} 
body { 
 margin-left: 10px; 
 margin-top: 10px; 
 margin-right: 10px; 
 margin-bottom: 10px; 
} 
.STYLE1 { 
 font-size: 14px; 
 font-weight: bold; 
} 
--> 
</style> 
</head> 
<body> 
<div align="center"> 
<?php 
 $conn = mysql_connect("localhost","root","root") or die("数据库链接错误".mysql_error()); 
 mysql_select_db("db_database21",$conn) or die("数据库访问错误".mysql_error()); 
 mysql_query("set names gb2312"); 
?> 
</div> 
<table width="777" height="587" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.jpg"> 
 <tr> 
 <td width="149" height="200"> </td> 
 <td width="448"> </td> 
 <td width="158"> </td> 
 </tr> 
 <tr> 
 <td height="187"> </td> 
 <td align="center" valign="middle"> <form id="form1" name="form1" method="post" action="index.php"> 
 <table height="129" border="0" cellpadding="0" cellspacing="0"> 
  <tr> 
   <td width="100" height="30" align="right" valign="middle" scope="col"><span class="STYLE1">用户名:</span></td> 
  <td width="100" height="30" align="left" valign="middle" scope="col"><label for="textfield"></label> 
  <input name="username" type="text" id="username" size="24" /></td> 
  <td width="100" align="center" valign="middle" scope="col"> </td> 
  </tr> 
  <tr> 
  <td height="30" align="right" valign="middle" class="STYLE1" scope="col">密码:</td> 
  <td height="30" align="left" valign="middle" scope="col"><input name="password" type="password" id="password" size="25" /></td> 
  <td align="center" valign="middle" scope="col"> </td> 
  </tr> 
  <tr> 
  <td height="40" colspan="3" align="center" valign="middle" scope="col"><input type="image" name="imageField" src="images/bg2.JPG" />   
     <input type="image" name="imageField2" src="images/bg1.JPG" onclick="form.reset();return false;" /></td> 
  </tr> 
 </table> 
 </form> 
 <?php 
 if(trim($_POST[username])!= "" and trim($_POST[password])!= ""){ 
  $usr = crypt(trim($_POST[username]),$_POST[username]); 
  $pwd = crypt(trim($_POST[password]),$_POST[password]); 
  $sql = "select * from tb_user where username = '".$usr."' and password='".$pwd."'"; 
  $rst = mysql_query($sql,$conn); 
  $result=mysql_num_rows($rst); 
  if($result>0){ 
   echo "<font color='red'>用户登录成功。</font>"; 
  }else{ 
   echo "<font color='green'>用户登录失败!</font>"; 
  } 
 }else{ 
  echo "请认真填写用户名和密码!"; 
 } 
?></td> 
 <td> </td> 
 </tr> 
 <tr> 
 <td height="200"> </td> 
 <td> </td> 
 <td> </td> 
 </tr> 
</table> 
</body> 
</html>

四、运行结果

php使用crypt()函数进行加密

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

PHP 相关文章推荐
谈谈新手如何学习PHP
Dec 14 PHP
php与paypal整合方法
Nov 28 PHP
php数组的一些常见操作汇总
Jul 17 PHP
PHP中用hash实现的数组
Jul 17 PHP
php判断上传的Excel文件中是否有图片及PHPExcel库认识
Jan 11 PHP
php和js如何通过json互相传递数据相关问题探讨
Feb 26 PHP
深入PHP中慎用双等于(==)的详解
Jun 06 PHP
php MessagePack介绍
Oct 06 PHP
PHP动态生成javascript文件的2个例子
Apr 11 PHP
CodeIgniter使用smtp服务发送html邮件的方法
Jun 10 PHP
PHP实现的链式队列结构示例
Sep 15 PHP
使用laravel的Eloquent模型如何获取数据库的指定列
Oct 17 PHP
微信封装的调用微信签名包的类库
Jun 08 #PHP
微信公众号实现会员卡领取功能
Jun 08 #PHP
php图像验证码生成代码
Jun 08 #PHP
php面向对象的用户登录身份验证
Jun 08 #PHP
php实现用户注册密码的crypt加密
Jun 08 #PHP
php封装一个异常的处理类
Jun 08 #PHP
php简单构造json多维数组的方法示例
Jun 08 #PHP
You might like
40年前的这部特摄片恐龙特级克塞号80后的共同回忆
2020/03/08 日漫
php下通过POST还是GET来传值
2008/06/05 PHP
php文件上传、下载和删除示例
2020/08/28 PHP
详解PHP swoole process的使用方法
2017/08/26 PHP
jQuery版Tab标签切换
2011/03/16 Javascript
js查错流程归纳
2012/05/04 Javascript
eval的两组性能测试数据
2012/08/17 Javascript
Javascript中的String对象详谈
2014/03/03 Javascript
JavaScript里四舍五入函数round用法实例
2015/04/06 Javascript
JavaScript动态检验密码强度的实现方法
2016/11/09 Javascript
JS闭包用法实例分析
2017/03/27 Javascript
jQuery中map函数的两种方式
2017/04/07 jQuery
基于Node.js的大文件分片上传示例
2019/06/19 Javascript
JS实现京东商品分类侧边栏
2020/12/11 Javascript
在Python的Flask框架下使用sqlalchemy库的简单教程
2015/04/09 Python
设计模式中的原型模式在Python程序中的应用示例
2016/03/02 Python
Python机器学习算法之k均值聚类(k-means)
2018/02/23 Python
Numpy之random函数使用学习
2019/01/29 Python
基于sklearn实现Bagging算法(python)
2019/07/11 Python
在python Numpy中求向量和矩阵的范数实例
2019/08/26 Python
python3 tkinter实现添加图片和文本
2019/11/26 Python
python 实现保存最新的三份文件,其余的都删掉
2019/12/22 Python
使用python快速实现不同机器间文件夹共享方式
2019/12/22 Python
Keras: model实现固定部分layer,训练部分layer操作
2020/06/28 Python
Django视图、传参和forms验证操作
2020/07/15 Python
Python读取多列数据以及用matplotlib制作图表方法实例
2020/09/23 Python
英国和爱尔兰最大的地毯零售商:Kukoon
2018/12/17 全球购物
业务员岗位职责
2013/11/16 职场文书
高中班主任评语大全
2014/04/25 职场文书
工地宣传标语
2014/06/18 职场文书
电气工程及其自动化专业求职信
2014/06/23 职场文书
党员干部三严三实心得体会
2014/10/13 职场文书
终止劳动合同证明书样本
2014/11/19 职场文书
离婚协议书样本
2015/01/26 职场文书
2015年秋季新学期寄语
2015/03/25 职场文书
教师节老师寄语
2015/05/28 职场文书