Home  >  Article  >  Backend Development  >  How to use thinkPHP to lock your account after three incorrect login passwords

How to use thinkPHP to lock your account after three incorrect login passwords

php中世界最好的语言
php中世界最好的语言Original
2018-05-28 10:45:212437browse

This time I will show you how to use thinkPHP to lock the account after three incorrect login passwords. How to use thinkPHP to lock the account after three incorrect login passwords. What are the precautions?. Here are the practical cases. Let’s take a look. take a look.

The table in the database needs to have the number of control data name, pwd, number

Whenever you enter an incorrect password, number-1 in the database will be locked when it is equal to 0

public function login_do(){
    //账号
    $username=$_POST['username'];
    //密码
    $pwd=$_POST['pwd'];
    $user=M('表名');
    $list=$user->where("username='$username'")->find();
    $time=date("Ymd",time());
    if($list['num']==0){
      if($list['time']!=$time+1){
        $this->error("您的账号已被锁定");
      }
    }
    if($list){
      if($list['pwd']==$pwd){
        $data['id']=$list['id'];
        $data['num']=3;
        $user->save($data);
        $this->success("登陆成功");
      }else{
        $list['num']=--$list['num'];
        $data['num']=$list['num'];
        $data['id']=$list['id'];
        $data['time']=$time;
        $user->save($data);
        $this->error("密码错误,还可以输入".$list['num']."次");
      }
    }else{
      $this->error("账号错误");
    }
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to implement ADODB transaction processing in PHP

How to use PHP to sort binary trees

The above is the detailed content of How to use thinkPHP to lock your account after three incorrect login passwords. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn