一个小时内密码错误超过5次封号

之前写的一段代码,在用着呢,如果是注册ip则可以登录。:

记录在这里一下:

实现: 一个小时内密码错误超过5次封号 和记录 错误 log

[code lang=”php”]

public function loginerrorcheck($uname){//登录错误记录
$this->verifyCodeffff();
$this_time = time();
$uerror =M("UserLoginError");
$rs = $uerror->where("username=’".$uname."’")->find();
$ip=get_client_ip();
if(empty($rs)){
$data[‘username’]=$uname;
$data[‘errortime’]=time();
$data[‘errorcount’]=1;
$data[‘doip’]=$ip;
$uerror->add($data);
}else{
if($this_time – $rs[‘errortime’]>=1*24*3600 && $rs[‘errorcount’]<5){
$data[‘username’]=$uname;
$data[‘errortime’]=time();
$data[‘errorcount’]=1;
$data[‘doip’]=$ip;
$uerror->where("username=’".$uname."’")->save($data);
//}elseif($this_time – $rs[‘errortime’]>=3*24*3600 && $rs[‘errorcount’]>10){
}else{
$uerror->where("username=’".$uname."’")->setField("errortime",$this_time);
$uerror->where("username=’".$uname."’")->setInc(‘errorcount’);
}

}
$count = $this->geterrorcount($uname,$ip);
if($count>=5){
M("User")->where("username=’".$uname."’")->setField("account_status",3);
$this->ajaxReturn(‘failure’,"您的帐号已被锁定,请联系: cs@mechanist.co",0);
}

}
public function geterrorcount($uname,$ip){
//$ip=get_client_ip();
$uerror =M("UserLoginError");
$count = $uerror->where("username=’".$uname."’")->getField(‘errorcount’);
if($count>10){
$regip = M("User")->where("username=’".$uname."’")->getField(‘regip’);
if($ip == $regip){
$uerror->where("username=’".$uname."’")->setField("errorcount",1);
return 1;
}else{
return $count;
}
}
}
[/code]