nojimage / cakephp-login-attempts
CakePHP 登录尝试插件
v3.0.2
2024-03-01 14:44 UTC
Requires
- php: ^8.1
- cakephp/authentication: ^3.0
- cakephp/cakephp: ^5.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.1
- cakephp/migrations: ^4.0
- phpunit/phpunit: ^10.1
Suggests
- cakephp/authentication: To use FormAuthenticator.
README
需求
- CakePHP >= 5.0
- CakePHP 认证插件
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require nojimage/cakephp-login-attempts"^3.0
加载插件
通过在项目的 src/Application.php
文件中添加以下语句来加载插件:
$this->addPlugin('LoginAttempts');
创建表
运行迁移命令
bin/cake migrations migrate -p LoginAttempts
用法
使用 LoginAttempts.Form
验证器代替 Form
。
如果使用认证插件
$service->loadAuthenticator('LoginAttempts.Form', [
'fields' => ['username' => 'email'],
'attemptLimit' => 5,
'attemptDuration' => '+5 minutes',
]);
LoginAttempts.Form 选项
attemptLimit
如果用户的登录失败次数在 attemptDuration
期间超过 attemptLimit
,则不允许用户登录。
默认: 5
attemptDuration
如果用户的登录失败次数在 attemptDuration
期间超过 attemptLimit
,则不允许用户登录。
默认: +5 minutes'
attemptAction
为该键存储尝试次数。当有多个登录表单且需要分别设置限制时使用。
默认: 'login'
attemptsStorageModel
用于记录失败登录和检查失败登录数量的模型。
默认: 'LoginAttempts.Attempts'