php 密码错误5次限制登录接口(微擎框架)
public function doPageLogin(){
global $_GPC, $_W;
$errno = 0;
$message = 'success';
$mobile = $_GPC['mobile'];
$post_password = $_GPC['password'];
$data = pdo_fetch("SELECT id,mobile,password,try,login_time,locktime,status FROM " . tablename('wx_school_user')."WHERE mobile = $mobile");
if($data['status'] == 1){
if(TIMESTAMP-$data['locktime']>3600){
$data['status'] = 0;
pdo_update('wx_school_user'.$data,array('mobile'=>$mobile));
}
$errno = 2;
$message = '账号已被锁定,请一小时后再登录';
}
$password = $this->getPassword($mobile, $post_password, $data['login_time']);
if ($data['password'] != $password){
$errno = 3;
$message = '密码错误';
if($data['try']<5){
$data['try']+=1;
pdo_update('wx_school_user',['try'=>$data['try']],array('id'=>$data['id']));
}else{
$data['status'] = 1;
$data['try'] = 0;
$data['locktime'] = TIMESTAMP;
pdo_update('wx_school_user',['try'=>$data['try'],'locktime'=>$data['locktime'],'status'=>$data['status']],array('id'=>$data['id']));
$errno = 2;
$message = '密码错误五次,账号已被锁定,请一小时后再登录';
}
}else{
$login_time = TIMESTAMP;
$password = $this->getPassword($mobile, $post_password, $login_time);
pdo_update('wx_school_user', ['password'=>$password, 'login_time'=>$login_time, 'try'=>0, 'locktime'=>0 ,'status'=>0]);
}
return $this->result($errno, $message, $data);
}
```private function getPassword($mobile, $password, $time = 0) : String
{
$salt = intval($time+$mobile);
return md5($password . $salt);
}