2017 © Pedro Peláez
 

package track-attempts

Track and limit any auth, OTP, or any other type of action.

image

machaven/track-attempts

Track and limit any auth, OTP, or any other type of action.

  • Thursday, July 20, 2017
  • by machaven
  • Repository
  • 2 Watchers
  • 1 Stars
  • 414 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 17 % Grown

The README.md

Track Attempts Library

A handy library to track any type of action and limit the amount of attempts made in a period of time frame., (*1)

Useful things to track and limit:, (*2)

  • 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:, (*3)

Use tags for version 1.x when used with Laravel version less than 5.8, (*4)

composer require machaven/track-attempts:^1.0, (*5)

Use tags for version 2.x when used with Laravel version 5.8+, (*6)

composer require machaven/track-attempts:^2.0, (*7)

If used with predis driver:, (*8)

composer require machaven/track-attempts:^2.0, (*9)

Class Configuration

Minimum Configuration, (*10)

$config = ['driver' => 'predis', userIdentifier' => $username];
$attempts = (new \Machaven\TrackAttempts\TrackAttempts($config))->getDriver();

Full Configuration, (*11)

$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., (*12)

Predis Driver Configuration

The predis driver requires redis settings to be configured in a .env file in your project root folder., (*13)

Example .env:, (*14)

REDIS_SCHEME=tcp
REDIS_HOST=localhost
REDIS_PASSWORD=
REDIS_PORT=6379
REDIS_DB=0
REDIS_PROFILE=3.2

Usage

Keeping count, (*15)

>>> $attempts->increment();
=> true

Getting the count, (*16)

>>> $attempts->getCount();
=> 1

Checking if the limit is reached, (*17)

>>> $attempts->isLimitReached();
=> false

Clearing all attempts, (*18)

>>> $attempts->clear();
=> true

Checking the time left before the count expires (in seconds), (*19)

>>> $attempts->getTimeUntilExpired();
=> 188

Incrementing attempts, (*20)

>>> $attempts->increment();

Using increment to track and check (example of max limit of 3 attempts), (*21)

>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> true
>>> $attempts->incrementAndCheckLimit();
=> false

The Versions

20/07 2017

dev-master

9999999-dev

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

20/07 2017

1.0.6

1.0.6.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

15/07 2017

1.0.5

1.0.5.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

14/07 2017

1.0.4

1.0.4.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

02/07 2017

1.0.3

1.0.3.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

02/07 2017

1.0.2

1.0.2.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

02/07 2017

1.0.1

1.0.1.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit

02/07 2017

1.0.0

1.0.0.0

Track and limit any auth, OTP, or any other type of action.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by David Olivier

laravel cache auth redis otp track limit