PHP100 2019-03-27
算法 | Salt长度 |
CRYPT_STD_DES | 2-character (Default) |
CRYPT_EXT_DES | 9-character |
CRYPT_MD5 | 12-character beginning with $1$ |
CRYPT_BLOWFISH | 16-character beginning with $2$ |
代码如下:
<!--check_user_crypt.php:使用crypt() 函数验证用户----------------> <?php $user_name=$_POST["user_name"]; require_once("sys_conf.inc"); //系统配置文件,包含数据库配置信息 //连接数据库 $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD); mysql_select_db($DBNAME); //选择数据库my_chat //查询是否存在登录用户信息 $str="select name,password from user where name ='$user_name'"; $result=mysql_query($str,$link_id); //执行查询 @$rows=mysql_num_rows($result); //取得查询结果的记录笔数 $user_name=$_SESSION["user_name"]; $password=$_POST["password"]; $salt = substr($password, 0, 2); $password_en=crypt($password,$salt); //使用crypt()对用户密码进行加密 //对于老用户 if($rows!=0) { list($name,$pwd)=mysql_fetch_row($result); //如果密码输入正确 if($pwd==$password_en) { $str="update user set is_online =1 where name ='$user_name' and password='$password_en'"; $result=mysql_query($str, $link_id);//执行查询 require("main.php"); //转到聊天页面 } //密码输入错误 else { require("relogin.php"); } } //对于新用户,将其信息写入数据库 else { $str="insert into user (name,password,is_online) values('$user_ name','$password_en',1)"; $result=mysql_query($str, $link_id); //执行查询 require("main.php"); //转到聊天页面 } //关闭数据库 mysql_close($link_id); ?>
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh