tp Framework of thinkPHP Realizes the Function of Locking Account after Three Login Password Errors
- 2021-10-11 17:52:19
- OfStack
This article describes the example of tp framework (thinkPHP) to achieve three login password error after locking the function of the account. Share it for your reference, as follows:
The tables in the database need to control the number of data name, pwd and number
Whenever you enter the wrong password, the number-1 in the database is locked when it is equal to 0
public function login_do(){
// Account number
$username=$_POST['username'];
// Password
$pwd=$_POST['pwd'];
$user=M(' Table name ');
$list=$user->where("username='$username'")->find();
$time=date("Ymd",time());
if($list['num']==0){
if($list['time']!=$time+1){
$this->error(" Your account has been locked ");
}
}
if($list){
if($list['pwd']==$pwd){
$data['id']=$list['id'];
$data['num']=3;
$user->save($data);
$this->success(" Successful login ");
}else{
$list['num']=--$list['num'];
$data['num']=$list['num'];
$data['id']=$list['id'];
$data['time']=$time;
$user->save($data);
$this->error(" Wrong password, you can also enter ".$list['num']." Times ");
}
}else{
$this->error(" Error account number ");
}
}
Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".
I hope this article is helpful to PHP programming based on ThinkPHP framework.