- /*
- 1.产生随机数
- 2.插入表
- 3.查询
- 4.返回yes
- */
- function mak() //生成卡号密码算法 可替换;
- {
- $str=md5(microtime());
- $pass=substr($str,-12);
- return $pass;
- }
- ///////////////生成卡号密码并存入数据库$times=你想添加的卡号密码条数////////////////
- 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);//选择数据库
-
- $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());
- }
- }
- ///////////////////验证卡号密码是否正确 参数为卡号 密码///////////////////////
- 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!";//直显式;
- //if($row[0]==$str1)return true;else return false;//接口式;
- }
- ////////////////////////////////////////////////////////////////////////////
- //用法:
- sqlconn(5);
- sqlauth('207a2c9dac2d','3a97d69421c6')
- ?>
复制代码
|