- /*
- 1. Generate random numbers
- 2. Insert into table
- 3. Query
- 4. Return yes
- */
- function mak() //Generate card number password algorithm can be replaced;
- {
- $str=md5(microtime());
- $pass=substr($str,-12);
- return $pass;
- }
- ///////////////Generate card number password And store it in the database $times=the number of card numbers and passwords you want to add////////////////
- function sqlconn($times)
- {
- $con=mysql_connect("127.0.0.1 ","root","");
- if(!$con)
- {
- die('Connect database............[ERROR]:'.mysql_error() );
- }
- else echo "Connect database server............[OK]
";
-
- $cmd="CREATE DATABASE num_psw";
-
- if (mysql_query($cmd,$con))echo "Creat database............[OK]
";
- else
- {
- echo 'Creat database.. ............[ERROR]:'.mysql_error()."
";
- }
-
- mysql_select_db("num_psw",$con);//Select database
-
- $cmd="CREATE table numpsw(auth1 varchar(25),auth2 varchar(25))";
-
- if(mysql_query($cmd,$con))echo "Creat table..... ......[OK]
";
- else
- {
- echo 'Creat table............[ERROR]:'.mysql_error(). "
";
- }
- for($i=0;$i<$times;$i++)
- {
- $tmp1=mak();
- $tmp2=mak();
- $cmd="insert into numpsw values('{$tmp1}', '{$tmp2}')";
- if(mysql_query($cmd,$con))echo "Creat num............ ..[OK]
num is:$tmp1 psw is:$tmp2 ";
- else die('Creat num............ [ERROR]:'.mysql_error());
- }
- }
- ///////////////////Verify whether the card number and password are correct. The parameter is the card number and password////// //////////////////
- function sqlauth($str1,$str2)
- {
- $con=mysql_connect("127.0.0.1","root","");
- mysql_select_db("num_psw",$con);
- $cmd="SELECT * FROM numpsw WHERE auth2='{$str2}'";
- $res=mysql_query($cmd,$con);
- $row = mysql_fetch_array($ res);
- if($row[0]==$str1)echo "Auth success!";else echo "Auth failed!";//Direct explicit form;
- //if($row[0]==$ str1)return true;else return false;//Interface type;
- }
- ////////////////////////////////// ////////////////////////////////////////////
- //Usage:
- sqlconn (5);
- sqlauth('207a2c9dac2d','3a97d69421c6')
- ?>
Copy code
|