需要用到 jquery 以及 md5 相关javascrip方法. 代码中直接引用了外部链接. 如果运行出现状况, 请单独下载,修改代码.
演示数据只有一个用户 id:test. passwd:abc123. 用文本存放数据. 简单演示. 喜欢记得收藏, 转载请注明出处.
<?php define('H_MAX', (256*8)-1); @ $a = isset($_GET['a']); @ $id = $_POST['id']; @ $passwd = $_POST['passwd']; if($a) { $mstr = get_mstr(); $hstr = get_hstr(); // $hstr = 256*2-1; $ua = get_u_i(); $str = md5($ua['passwd'].dechex($mstr+$hstr).dechex($hstr)); $ua['str'] = dechex($hstr); set_u_i($ua); echo json_encode(array('mstr'=>$mstr, 'str'=>$str)); exit; } if(isset($_POST['id'])) { $st = false; $ua = get_u_i(); if($id && ($ua['id'] == $id) && (md5($ua['passwd'].$ua['str']) == $passwd)) { $st=true; } if($st) { $ua['str'] = dechex(get_hstr()); set_u_i($ua); echo <<<EOT <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>test login</title> </head> <body> 胜利大联欢. </body> </html> EOT; } else { } exit; } $ua = array('id'=>'test', 'passwd'=>md5('abc123'), 'str'=>''); set_u_i($ua); function get_mstr() { $t = explode(' ', microtime()); $time = $t[0] * 1000; $time = intval($time); //$time = dechex($time); return $time; } function get_hstr() { $h_max = H_MAX; return mt_rand(0, $h_max); } function get_u_i() { $file = 'test_login.txt'; $str = file_get_contents($file); $str = trim($str); @list($id, $passwd, $str) = explode("t", $str); return array('id'=>$id, 'passwd'=>$passwd, 'str'=>$str); } function set_u_i($ua) { $file = 'test_login.txt'; file_put_contents($file,implode("t", $ua)); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>test login</title> <script src="http://fuck.thinksaas.cn/get/http://pajhome.org.uk/crypt/md5/2.2/md5-min.js"type="text/javascript"></script> <script src="http://fuck.thinksaas.cn/get/http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"type="text/javascript"></script> <script type="text/javascript"> $(function(){ var h_max = <?=H_MAX;?>; var last_id=''; var mstr=''; var str=''; var $id = $('#id'); var $passwd = $('#passwd'); var $form = $("form:first"); $id.focus(); $id.blur(function(a,b){ if(last_id == $id.val()) return ; last_id = $id.val(); var o = s1(); if(o) { mstr = o.mstr; str = o.str; } }); $form.submit(function() { $('#submit').prop('disabled',true); var p = md5($passwd.val()); var st=0; for(var i=0;i<=h_max;i++){ var t=''+(p)+(parseInt(mstr)+parseInt(i)).toString(16)+i.toString(16); if(str==md5(t)) { st=1; $passwd.val(md5(p+i.toString(16))); break; }; } if(!st) { } //$('#submit').attr('disabled','disabled'); return true; }); function md5(s) { return hex_md5(s); } function s1(){ var a; var e; $.ajax({ url:"?a", type:"POST", timeout:10000, data: {}, dataType:"json", async: false, error: function(XMLHttpRequest, textStatus, errorThrown){ e=true; //alert(textStatus+"&"+errorThrown); }, success: function(data, textStatus){ a = data; } }); if(e) return false; return a; } }); </script> </head> <body> <form action=""method="post"enctype="application/x-www-form-urlencoded"name="form1"target="_self"id="from1"> <label>用户名: <input name="id"type="text"id="id"> </label> <label>密码: <input name="passwd"type="password"id="passwd"> </label> <label> <input name="submit"type="submit"id="submit"value="登录"> </label> </form> </body> </html>