当前位置:网站首页>PHP实现登录失败三次需要输入验证码需求
PHP实现登录失败三次需要输入验证码需求
2022-08-02 21:44:00 【慢慢成长1688】
具体场景是这样的:后台登录,前三次不需要输入验证码,在登录失败三次后,出现输入验证码的框,并且要验证是否正确。
登录三次失败后:
前端代码(一小段)
后端登录逻辑:
public function index()
{
$model = new UserModel;
$loginError = (int)session('admin_login_error');
if ($this->request->isPost()) {
$captchaObj = new Captcha();
$username = $this->request->post('username/s');
$password = $this->request->post('password/s');
$captcha = $this->request->post('captcha/s');
$data = [];
if ($loginError >= 3) {
if (empty($captcha)) {
return $this->error('请输入验证码');
}
if (!captcha_check($captcha)) {
return $this->error('验证码错误');
}
}
if (!$model->login($username, $password)) {
$loginError = ($loginError+1);
session('admin_login_error', $loginError);
$data['token'] = $this->request->token();
$data['captcha'] = $loginError >= 3 ? captcha_src() : '';
return $this->error($model->getError(), url('index'), $data);
}
//登录成功,重置登录错误次数
session('admin_login_error', 0);
return $this->success('登陆成功,页面跳转中...', url('index/index'));
}
//判断是否已经登录
if ($model->isLogin()) {
$this->redirect(url('index/index', '', true, true));
}
$this->view->engine->layout(false);
$this->assign('loginError', $loginError);
return $this->fetch();
}
边栏推荐
猜你喜欢
随机推荐
UDP(用户数据报协议)
CS5213芯片|HDMI to VGA转换头芯片资料分享
网络运维系列:健康检查的方式
LeetCode 2360. 图中的最长环 基环树找环+时间戳
JumpServer open source bastion machine completes Loongson architecture compatibility certification
Ansible installation and configuration
js函数防抖和函数节流及其他使用场景
一群搞社区的人
牛客每日刷题之链表
How to seize the new trend of NFT, yuan|universe|universe?
搭建Spark开发环境(第二弹)
win10安全中心设置不扫描某个文件夹的方法
第十章 时序与延迟
你我都会遇到的需求:如何导出MySQL中的数据~ 简单!实用!
宝塔搭建实测-基于ThinkPHP5.1的wms进销存源码
IP协议(网际协议)
在迁移测试中,源表、中间表、目标表的迁移规则
Auto.js脚本程序打包
GameStop NFT 市场分析
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析