machaven/track-attempts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

machaven/track-attempts

最新稳定版本:2.0.3

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

统计信息

  • 总下载量: 4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固