machaven/track-attempts
Composer 安装命令:
composer require machaven/track-attempts
包简介
Track and limit any auth, OTP, or any other type of action.
README 文档
README
A handy library to track any type of action and limit the amount of attempts made in a period of time frame.
Useful things to track and limit:
- Login attempts.
- One Time Pin (OTP) attempts.
- Any thing else you want to limit or monitor.
Features
- Track on any metric you want, like email, username, etc.
- Configurable limits.
- Multiple backend drivers:
- Redis (Predis Client)
- Laravel (Cache Facade)
Install
If using with the Laravel Drivers:
Use tags for version 1.x when used with Laravel version less than 5.8
composer require machaven/track-attempts:^1.0
Use tags for version 2.x when used with Laravel version 5.8+
composer require machaven/track-attempts:^2.0
If used with predis driver:
composer require machaven/track-attempts:^2.0
Class Configuration
Minimum Configuration
$config = ['driver' => 'predis', userIdentifier' => $username];
$attempts = (new \Machaven\TrackAttempts\TrackAttempts($config))->getDriver();
Full Configuration
$config = [
'driver' => 'predis', // Driver to use ('predis' or 'laravel')
'userIdentifier' => $username, // A variable with a unique identifier for the session/user
'maxAttempts' => 3, // Max attempts limit
'systemName' => 'my-website', // System Identifier used in cache key prefix.
'ttlInMinutes' => 5, // Keep track of attempts in a five minute period.
'actionName' => 'login', // The name of the action you are tracking.
];
$attempts = (new \Machaven\TrackAttempts\TrackAttempts($config))->getDriver();
The configuration above will create a key named: my-website:login:$username.
Predis Driver Configuration
The predis driver requires redis settings to be configured in a .env file in your project root folder.
Example .env:
REDIS_SCHEME=tcp
REDIS_HOST=localhost
REDIS_PASSWORD=
REDIS_PORT=6379
REDIS_DB=0
REDIS_PROFILE=3.2
Usage
Keeping count
>>> $attempts->increment();
=> true
Getting the count
>>> $attempts->getCount();
=> 1
Checking if the limit is reached
>>> $attempts->isLimitReached();
=> false
Clearing all attempts
>>> $attempts->clear();
=> true
Checking the time left before the count expires (in seconds)
>>> $attempts->getTimeUntilExpired();
=> 188
Incrementing attempts
>>> $attempts->increment();
Using increment to track and check (example of max limit of 3 attempts)
>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> false
machaven/track-attempts 适用场景与选型建议
machaven/track-attempts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.01k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「cache」 「auth」 「laravel」 「otp」 「track」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 machaven/track-attempts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 machaven/track-attempts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 machaven/track-attempts 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Laravel Multiauth package
Microservice RPC through message queues.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
The CodeIgniter Redis package
贝嘟分布式缓存扩展
统计信息
- 总下载量: 4.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-02