這篇文章主要介紹了tp架構(thinkPHP)實現三次登陸密碼錯誤之後鎖定帳號功能,結合執行個體形式分析了基於thinkPHP登陸判斷、標誌位元運算等操作實現密碼帳號鎖定功能,需要的朋友可以參考下
本文執行個體講述了tp架構(thinkPHP)實現三次登陸密碼錯誤之後鎖定帳號功能。分享給大家供大家參考,具體如下:
資料庫中的表需要有控制資料的條數name,pwd,number
每當你輸入錯誤的密碼時候,資料庫中的number-1,等於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("帳號錯誤"); }}
以上就是本篇文章的全部內容了,感謝大家閱讀。更多請關注topic.alibabacloud.com!