Algorithm | Salt length |
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$ |
1 <!--check_user_crypt.php: Use the crypt() function to verify the user----------------> 2 <?php 3 $user_name=$_POST["user_name"]; 4 require_once("sys_conf.inc"); //System configuration file, including database configuration information 5 6 //Connect to the database 7 $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD); 8 mysql_select_db($DBNAME); //Select database my_chat 9 10 //Query whether there is logged in user information 11 $str="select name,password from user where name ='$user_name'"; 12 $result=mysql_query($str,$link_id); //Execute query 13 @$rows=mysql_num_rows($result); //The number of records obtained from the query results 14 $user_name=$_SESSION["user_name"]; 15 $password=$_POST["password"]; 16 $salt = substr($password, 0, 2); 17 $password_en=crypt($password,$salt); //Use crypt() to encrypt the user password 18 19 //For old users 20 if($rows!=0) twenty one { 22 list($name,$pwd)=mysql_fetch_row($result); twenty three 24 //If the password is entered correctly 25 if($pwd==$password_en) 26 { 27 $str="update user set is_online =1 where name ='$user_name' and password='$password_en'"; 28 $result=mysql_query($str, $link_id);//Execute query 29 require("main.php"); //Go to the chat page 30} 31 //Password input error 32 else 33 { 34 require("relogin.php"); 35} 36 37 } 38 //For new users, write their information into the database 39 else 40 { 41 $str="insert into user (name,password,is_online) values('$user_ name','$password_en',1)"; 42 $result=mysql_query($str, $link_id); //Execute query 43 require("main.php"); //Go to the chat page 44} 45 //Close the database 46 mysql_close($link_id); 47?> |