PHPackages                             ognyk/yii2-login-blocker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. ognyk/yii2-login-blocker

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

ognyk/yii2-login-blocker
========================

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

1.3.0(8y ago)1720MITPHP

Since Nov 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ognyk/yii2-login-blocker)[ Packagist](https://packagist.org/packages/ognyk/yii2-login-blocker)[ RSS](/packages/ognyk-yii2-login-blocker/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

yii2-login-blocker
==================

[](#yii2-login-blocker)

[![Latest Stable Version](https://camo.githubusercontent.com/7aa809199804c706069bb09e8d1a6bafa12a2ae01463e853012fe25e0b841dad/68747470733a2f2f706f7365722e707567782e6f72672f6f676e796b2f796969322d6c6f67696e2d626c6f636b65722f762f737461626c65)](https://packagist.org/packages/ognyk/yii2-login-blocker)[![Total Downloads](https://camo.githubusercontent.com/f2182a424ce85a5f73d04b1ba78d3bc9efa87d2abf4502496a0152ba4f6ee1b0/68747470733a2f2f706f7365722e707567782e6f72672f6f676e796b2f796969322d6c6f67696e2d626c6f636b65722f646f776e6c6f616473)](https://packagist.org/packages/ognyk/yii2-login-blocker)[![License](https://camo.githubusercontent.com/de94b2370c235cd7f4533c44609bd86546377fb2d5fbb88e26e4d209579b28b7/68747470733a2f2f706f7365722e707567782e6f72672f6f676e796b2f796969322d6c6f67696e2d626c6f636b65722f6c6963656e7365)](https://packagist.org/packages/ognyk/yii2-login-blocker)

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

Installation
------------

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

Either run

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

```

or add

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

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

1. Add `loginBlocker` component to your [Yii2 configuration](http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#application-configurations)like this:

    ```
    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker'
        ]
    ]
    ```
2. Methods `loginBlocker`:

    ```
    /* Check if user can login */
    \Yii::$app->loginBlocker->check();

    /* Increment counter when wrong login or password */
    \Yii::$app->loginBlocker->block();
    ```
3. Use `loginBlocker`:

    ```
    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
---------------

[](#advanced-config)

1. More parameters:

    ```
    '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:

    To use notification by e-mail configure `\Yii::$app->mailer`.

    All parameters without `mails` are optional.

    ```
    'components' => [
        'loginBlocker' => [
            'class' => '\ognyk\loginblocker\LoginBlocker',
            'mail' => [
                'subject' => 'New subject with user IP {ip}',
                'content' => 'User IP {ip}Date: {date}{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:

    You can pass custom params to your alert e-mail.

    ```
    $params = [
        'Username' => 'Cezar V',
        'Server' => 'torr-2378-45'
    ];

    \Yii::$app->loginBlocker->check($params)
    ```
4. Insert result to database:

    To use database configure `\Yii::$app->db`.

    You can easily add custom parameters f.e. {params.Username} or {params.Server}.

    Example of database table you can find in migrations folder.

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

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

3145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0030862a148fad956d9911c16871827f0d635f7ae730a1831309f4b1239b1c3b?d=identicon)[ognyk](/maintainers/ognyk)

---

Top Contributors

[![ognyk](https://avatars.githubusercontent.com/u/18393637?v=4)](https://github.com/ognyk "ognyk (14 commits)")

---

Tags

yii2loginblockban

### Embed Badge

![Health badge](/badges/ognyk-yii2-login-blocker/health.svg)

```
[![Health](https://phpackages.com/badges/ognyk-yii2-login-blocker/health.svg)](https://phpackages.com/packages/ognyk-yii2-login-blocker)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[sweelix/yii2-redis-rbac

PHP 5.6+ Redis / RBAC integration for the Yii framework

2411.8k](/packages/sweelix-yii2-redis-rbac)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
