2017 © Pedro Peláez
 

library laraflood

Flood protection for laravel 5

image

vincendev/laraflood

Flood protection for laravel 5

  • Thursday, May 17, 2018
  • by VincenDev
  • Repository
  • 2 Watchers
  • 0 Stars
  • 149 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 80 % Grown

The README.md

Laraflood - Antiflood system for Laravel using Cache

This tool designed for limiting some user requests., (*1)

This tool is based on: ircop/Laraflood, I have added / modified things that have been useful for my current project and I publish it in case it can be useful to someone!, (*2)

INSTALL

1: install via composer, (*3)

composer require vincendev/laraflood

If you're using laravel 5.5: steps 2 and 3 are not necessary., (*4)

2: add service provider to providers array in config/app.php:, (*5)

Vincendev\Laraflood\LarafloodServiceProvider::class,

3: add facade alias to aliases array in config/app.php:, (*6)

'Laraflood' => Vincendev\Laraflood\FacadeLaraflood::class,

Usage

Checking for record existance with given identity and add attempt., (*7)

$identity - can be ip-address, user id, anything unique. Default is ip-address., (*8)

$action - What is the user trying to do? Submit-post, Login, Search, etc. Default is 'default'., (*9)

$maxAttempts - How many attempts do you want to give the user? Default is 5., (*10)

$minutes - Waiting time after attempts are over. Default is 5 minutes., (*11)


Laraflood::check( $identity = 'ip', $action = 'default', $maxAttempts = 5, $minutes = 5 ); Laraflood::check(); Laraflood::check( $user->id , 'submit-comment'); Laraflood::check( $user->id , 'report-comment', 1, 5); /* Return bool */

Only check without add attempt., (*12)

Laraflood::checkOnly( $identity = 'ip', $action = 'default', $maxAttempts = 5, $minutes = 5 );
Laraflood::checkOnly();
Laraflood::checkOnly( $user->id , 'submit-comment');
Laraflood::checkOnly( $user->id , 'report-comment', 1, 5);

/* Return bool */

Add attempt for given $identity with ·$action on given $minutes. 'ip' by default is the real user ip., (*13)

Laraflood::addAttempt( $identity = 'ip', $action = 'default', $minutes = 5 );
Laraflood::addAttempt();
Laraflood::addAttempt('ip', 'like-post');
Laraflood::addAttempt( $user->id ,'default', 5 );

/* Void */

Get time left for given identity & action., (*14)


Laraflood::timeLeft( $identity = 'ip', $action = 'default'); Laraflood::timeLeft(); Laraflood::timeLeft( 'ip', 'like-post'); /* Return string */ # X hours # X minutes # X seconds

Returns array for given identity & action, (*15)


Laraflood::get($identity = 'ip', $action = 'default') Laraflood::get(); Laraflood::get( 'ip', 'like-post'); /* array:3 [▼ "action" => "default" "attempts" => 1 "expiration" => "2019-09-18 19:51:01.175237" ] */

Examples:

Limiting wrong login attempts for given IP address:

This example limiting wrong login attempts from one ip-address to 5 tryes per 20 minutes:, (*16)

public function postLogin()
{

/**
* If thes user ip has >= 5 failed login attempts in last 5 minutes, redirect user
* back with error:
*/

    if( Laraflood::check( 'ip' , 'login', 5, 5 ) === FALSE )
        return redirect()->back()->withErrors(["AntiFlood Protection! Try again in ".Laraflood::timeLeft('ip','login')." ."]);

    /**
    * Your code here..
    */

}

Increment post views .

This code shows how increment post views only 1 view every 24 hours.., (*17)

public function incrementPostViews()
{
        $action = "post-visit:" . $post->id; // Post unique ID
        $visitsPerUser = 1;
        $minutes = 1440; // 24Hours
        if(Laraflood::checkOnly('ip', $action, $visitsPerUser)){
            /**
            * Increment post views
            * Your code here..
            */
            Laraflood::addAttempt('ip', $action, $minutes);
        }

}

The Versions

17/05 2018

1.1.x-dev

1.1.9999999.9999999-dev

Flood protection for laravel 5

  Sources   Download

MIT

The Requires

 

by Vincen

laravel security spam antispam flood antiflood

17/05 2018

1.1.1

1.1.1.0

Flood protection for laravel 5

  Sources   Download

MIT

The Requires

 

by Vincen

laravel security spam antispam flood antiflood

17/05 2018

1.1.1.x-dev

1.1.1.9999999-dev

Flood protection for laravel 5

  Sources   Download

MIT

The Requires

 

by Vincen

laravel security spam antispam flood antiflood

17/05 2018

dev-revert-3-master

dev-revert-3-master

Flood protection for laravel 5

  Sources   Download

MIT

The Requires

 

by Vincen

laravel security spam antispam flood antiflood

12/05 2018

1.0.x-dev

1.0.9999999.9999999-dev

Flood protection for laravel 5

  Sources   Download

MIT GPLv2

The Requires

 

by Vincen

laravel security spam antispam flood antiflood

18/09 2017

1.0.0

1.0.0.0

Flood protection for laravel 5

  Sources   Download

GPLv2

The Requires

 

by Vincen

laravel security spam antispam flood antiflood