一、代码

$str = '应用crypt()函数进行单向加密!'; //声明字符串变量$str

echo '加密前$str的值为:'.$str;

$crypttostr = crypt($str); //对变量$str加密

echo '

加密后$str的值为:'.$crypttostr; //输出加密后的变量

?>

二、运行结果

参数不带salt,每次加密得出的密文都不一样。

加密前$str的值为:应用crypt()函数进行单向加密!

加密后$str的值为:$1$Re4.Gg4.$D.yd00xX0fFfIfp6KrKGN0

三、代码

使用crypt函数进行数据验证

$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");

?>

   
 
用户名: 
密码: 

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 "用户登录成功。";

}else{

echo "用户登录失败!";

}

}else{

echo "请认真填写用户名和密码!";

}

?>

 
   

四、运行结果

2e6f5e20332e21ff19647b422e2174b7.png

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

更多推荐