mindforce/attempt
Composer 安装命令:
composer require mindforce/attempt
包简介
A CakePHP plugin that helps to protect sensitive actions from brute force attacks
README 文档
README
A CakePHP 2.0 or 2.1 plugin that helps to protect sensitive actions from brute force attacks.
API
count($action)
Returns the number of failed attempts for a certain action.
limit($action, $limit = 5)
Returns false if the number of failed attempts is bigger than the passed limit.
fail($action, $duration = '+10 minutes')
Creates a failed attempt that counts towards the limit for the passed duration
reset($action)
Deletes all failed attempts for a certain action
cleanup()
Deletes all expired failed attempts from the database. This should be run via CakeShell (ideally as a CRON job) every now and then.
Schema
Run Console/cake schema create --plugin Attempt or manually make a table:
CREATE TABLE `attempts` (
`id` char(36) NOT NULL DEFAULT '',
`ip` varchar(64) DEFAULT NULL,
`action` varchar(32) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`expires` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ip` (`ip`,`action`),
KEY `expires` (`expires`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Example Implementation
<?php
class ExampleController extends AppController {
public $components = array(
'Attempt.Attempt'
);
public $loginAttemptLimit = 10;
public $loginAttemptDuration = '+1 hour';
public function login() {
// Form submitted?
if ( $formSubmitted = true ) {
// All required fields entered?
if ( $validFormData = true ) {
// Limit to 10 failed attempts
if ( $this->Attempt->limit('login', $this->loginAttemptLimit) ) {
// Validate user credentials
if ( $validCredentials = true ) {
// Log user in
} else {
// Invalid credentials, count as failed attempt for an hour
$this->Attempt->fail('login', $this->loginAttemptDuration);
$this->Session->setFlash('Unknown user or wrong password');
}
} else {
// User exceeded attempt limit
// Ideally show a CAPTCHA (ensuring this is not a robot
// without blocking out and frustrating users),
// otherwise show error message
$this->Session->setFlash('Too many failed attempts!');
}
} else {
// Invalid form data but keep it ambiguous
$this->Session->setFlash('Unknown user or wrong password');
}
}
}
}
Alternate Implementation (simple admin login)
<?php
class UsersController extends AppController {
public $components = array(
'Security',
'Attempt.Attempt'
);
public $loginAttemptLimit = 10;
public $loginAttemptDuration = '+1 hour';
public function admin_login() {
if (empty($this->data)) {
return;
}
// check for repeated login attempts
if ($this->Attempt->limit('admin_login', $this->loginAttemptLimit)) {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
// login was successful, redirect to admin menu
$this->redirect(array(
'controller' => 'users',
'action' => 'index',
'admin' => true
));
} else {
// increment the attempt counter
$this->Attempt->fail('admin_login', $this->loginAttemptDuration);
$this->Session->setFlash('Unknown user or wrong password.');
return;
}
}
} else {
// $loginAttemptLimit reached
$this->Session->setFlash('Login limit exceeded, please try again later.');
}
}
}
mindforce/attempt 适用场景与选型建议
mindforce/attempt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「cakephp」 「limit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mindforce/attempt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mindforce/attempt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mindforce/attempt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Rapid pagination without using OFFSET
Limit number of records that can be added to a SilverStripe GridField
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
Magento 2 Discount Amount Limiter
A Laravel Pulse card to track users & URL's that are being throttled by your Rate Limiters
统计信息
- 总下载量: 1.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-10-18