Home >Backend Development >PHP Tutorial >PHP implements point card number password generation

PHP implements point card number password generation

WBOY
WBOYOriginal
2016-07-25 08:45:341345browse
  1. /*
  2. 1. Generate random numbers
  3. 2. Insert into table
  4. 3. Query
  5. 4. Return yes
  6. */
  7. function mak() //Generate card number password algorithm can be replaced;
  8. {
  9. $str=md5(microtime());
  10. $pass=substr($str,-12);
  11. return $pass;
  12. }
  13. ///////////////Generate card number password And store it in the database $times=the number of card numbers and passwords you want to add////////////////
  14. function sqlconn($times)
  15. {
  16. $con=mysql_connect("127.0.0.1 ","root","");
  17. if(!$con)
  18. {
  19. die('Connect database............[ERROR]:'.mysql_error() );
  20. }
  21. else echo "Connect database server............[OK]
    ";
  22. $cmd="CREATE DATABASE num_psw";
  23. if (mysql_query($cmd,$con))echo "Creat database............[OK]
    ";
  24. else
  25. {
  26. echo 'Creat database.. ............[ERROR]:'.mysql_error()."
    ";
  27. }
  28. mysql_select_db("num_psw",$con);//Select database
  29. $cmd="CREATE table numpsw(auth1 varchar(25),auth2 varchar(25))";
  30. if(mysql_query($cmd,$con))echo "Creat table..... ......[OK]
    ";
  31. else
  32. {
  33. echo 'Creat table............[ERROR]:'.mysql_error(). "
    ";
  34. }
  35. for($i=0;$i<$times;$i++)
  36. {
  37. $tmp1=mak();
  38. $tmp2=mak();
  39. $cmd="insert into numpsw values('{$tmp1}', '{$tmp2}')";
  40. if(mysql_query($cmd,$con))echo "Creat num............ ..[OK]
    num is:$tmp1
    psw is:$tmp2
    ";
  41. else die('Creat num............ [ERROR]:'.mysql_error());
  42. }
  43. }
  44. ///////////////////Verify whether the card number and password are correct. The parameter is the card number and password////// //////////////////
  45. function sqlauth($str1,$str2)
  46. {
  47. $con=mysql_connect("127.0.0.1","root","");
  48. mysql_select_db("num_psw",$con);
  49. $cmd="SELECT * FROM numpsw WHERE auth2='{$str2}'";
  50. $res=mysql_query($cmd,$con);
  51. $row = mysql_fetch_array($ res);
  52. if($row[0]==$str1)echo "Auth success!";else echo "Auth failed!";//Direct explicit form;
  53. //if($row[0]==$ str1)return true;else return false;//Interface type;
  54. }
  55. ////////////////////////////////// ////////////////////////////////////////////
  56. //Usage:
  57. sqlconn (5);
  58. sqlauth('207a2c9dac2d','3a97d69421c6')
  59. ?>
Copy code

Click card, card number, php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn