首页 > php教程 > PHP源码 > 登录验证新思路,演示登录代码.

登录验证新思路,演示登录代码.

PHP中文网
发布: 2016-05-25 17:00:15
原创
1219 人浏览过

需要用到 jquery 以及 md5 相关javascrip方法. 代码中直接引用了外部链接. 如果运行出现状况, 请单独下载,修改代码.

演示数据只有一个用户 id:test. passwd:abc123. 用文本存放数据. 简单演示. 喜欢记得收藏, 转载请注明出处.

<?php


define(&#39;H_MAX&#39;, (256*8)-1); 

@ $a = isset($_GET[&#39;a&#39;]);
@ $id = $_POST[&#39;id&#39;];
@ $passwd = $_POST[&#39;passwd&#39;];

if($a) {
$mstr = get_mstr(); 
$hstr = get_hstr(); 
// $hstr = 256*2-1;
$ua = get_u_i(); 
$str = md5($ua[&#39;passwd&#39;].dechex($mstr+$hstr).dechex($hstr));
$ua[&#39;str&#39;] = dechex($hstr);
set_u_i($ua); 
echo json_encode(array(&#39;mstr&#39;=>$mstr, &#39;str&#39;=>$str));
exit;
}


if(isset($_POST[&#39;id&#39;])) {

$st = false;
$ua = get_u_i();
if($id && ($ua[&#39;id&#39;] == $id) && (md5($ua[&#39;passwd&#39;].$ua[&#39;str&#39;]) == $passwd)) {
$st=true;
}
if($st) { 
$ua[&#39;str&#39;] = 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(&#39;id&#39;=>&#39;test&#39;, &#39;passwd&#39;=>md5(&#39;abc123&#39;), &#39;str&#39;=>&#39;&#39;);
set_u_i($ua); 

function get_mstr() {
$t = explode(&#39; &#39;, 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 = &#39;test_login.txt&#39;;
$str = file_get_contents($file);
$str = trim($str);
@list($id, $passwd, $str) = explode("t", $str);
return array(&#39;id&#39;=>$id, &#39;passwd&#39;=>$passwd, &#39;str&#39;=>$str);
}

function set_u_i($ua) {
$file = &#39;test_login.txt&#39;;
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=&#39;&#39;;
var mstr=&#39;&#39;;
var str=&#39;&#39;;
var $id = $(&#39;#id&#39;);
var $passwd = $(&#39;#passwd&#39;);
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() {
$(&#39;#submit&#39;).prop(&#39;disabled&#39;,true);
var p = md5($passwd.val());
var st=0; 
for(var i=0;i<=h_max;i++){
var t=&#39;&#39;+(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) {

}
//$(&#39;#submit&#39;).attr(&#39;disabled&#39;,&#39;disabled&#39;);
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>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板