2021-01-19

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");
        //var_dump(pdo_debug());die;

        //判断当前登录账户是否被锁定
        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
    {
        // 登录时间+手机组成密码的盐,密码+盐MD5加密后生成密码
        $salt = intval($time+$mobile);
	    return md5($password . $salt);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值