- /*
- 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 {
- $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')
- ?>
复制代码
|
点卡, 卡号, php
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31