2017 © Pedro Peláez
 

yii2-extension yii2-login-blocker

Block/ban login for few minutes after 3 wrong login times.

image

ognyk/yii2-login-blocker

Block/ban login for few minutes after 3 wrong login times.

  • Wednesday, November 15, 2017
  • by ognyk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

yii2-login-blocker

Latest Stable Version Total Downloads License, (*1)

Block/ban login for few minutes after 3 wrong login times., (*2)

Installation

The preferred way to install this extension is through Composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist ognyk/yii2-login-blocker

or add, (*5)

"ognyk/yii2-login-blocker": "*"

to the require section of your composer.json file., (*6)

Usage

  1. Add loginBlocker component to your Yii2 configuration like this:, (*7)

    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker'
        ]
    ]
    
  2. Methods loginBlocker:, (*8)

    /* Check if user can login */
    \Yii::$app->loginBlocker->check();
    
    /* Increment counter when wrong login or password */
    \Yii::$app->loginBlocker->block();
    
  3. Use loginBlocker:, (*9)

    if (!\Yii::$app->loginBlocker->check()) {
        return ['error' => 'time_block'];
    }
    
    if ($model->login()) {
        // ... good action here
    } else {
        \Yii::$app->loginBlocker->block();
    
        return ['error' => 'wrong_credentials'];
    }
    

Advanced config

  1. More parameters:, (*10)

    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker',
            'time' => 300,              // Time to block/ban user in seconds (default 300 sec)
            'wrong_login_number' => 3,  // Number of wrong attempts (default 3 times)
        ]
    ]
    
  2. Notification of block/ban by e-mail:, (*11)

    To use notification by e-mail configure \Yii::$app->mailer., (*12)

    All parameters without mails are optional., (*13)

    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker',
            'mail' => [
                'subject' => 'New subject with user IP {ip}',
                'content' => 'User IP {ip}<br>Date: {date}<b>{params}',
                'sender' => [
                    'name' => 'Cezar II',
                    'mail' => 'mail@mail.com',
                ],
                'mails' => [
                    'admin1@mail.com',
                    'admin2@mail.com',
                    'admin3@mail.com',
                ],
            ]
        ]
    ]
    
  3. More information from login action:, (*14)

    You can pass custom params to your alert e-mail., (*15)

    $params = [
        'Username' => 'Cezar V',
        'Server' => 'torr-2378-45'
    ];
    
    \Yii::$app->loginBlocker->check($params)
    
  4. Insert result to database:, (*16)

    To use database configure \Yii::$app->db., (*17)

    You can easily add custom parameters f.e. {params.Username} or {params.Server}., (*18)

    Example of database table you can find in migrations folder., (*19)

    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker',
            'database' => [
                'name' => 'Login_blocker',
                'columns' =>  [
                    'ip' => '{ip}',
                    'created_datetime' => '{date}',
                    'username' => '{params.Username}', // More parameters from point 3
                ]
            ]
        ]
    ]
    

The Versions

15/11 2017

1.3.0

1.3.0.0

Block/ban login for few minutes after 3 wrong login times.

  Sources   Download

MIT

The Requires

 

by Bartosz Lewandowski

yii2 ban login block

15/11 2017

dev-master

9999999-dev

Block/ban login for few minutes after 3 wrong login times.

  Sources   Download

MIT

The Requires

 

by Bartosz Lewandowski

yii2 ban login block

15/11 2017

1.2.0

1.2.0.0

Block/ban login for few minutes after 3 wrong login times.

  Sources   Download

MIT

The Requires

 

by Bartosz Lewandowski

yii2 ban login block

10/11 2017

1.1.0

1.1.0.0

Block/ban login for few minutes after 3 wrong login times.

  Sources   Download

MIT

The Requires

 

by Bartosz Lewandowski

yii2 ban login block

09/11 2017

1.0.2

1.0.2.0

Blocked/Ban login for few minutes after 3 wrong login times.

  Sources   Download

MIT

The Requires

 

by Bartosz Lewandowski

yii2 ban login block

09/11 2017

1.0.1

1.0.1.0

Blocked login for few minutes after 3 wrong login times.

  Sources   Download

The Requires

 

by Bartosz Lewandowski

yii2 assets compress

07/11 2017

1.0.0

1.0.0.0

Blocked login for few minutes after 3 wrong login times.

  Sources   Download

The Requires

 

by Bartosz Lewandowski

yii2 assets compress