Store login failures, and disable after multiple failures.
The preferred way to install this extension is through composer.
Either run
composer require crestoff/yii2badlogin
or add
"crestoff/yii2badlogin" : "*"
to the require section of your composer.json
file.
Run the following migration
php yii migrate --migrationPath="vendor/crestoff/yii2badlogin/src/migrations" --interactive=0
Add the behavior to your login model.
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors[] = [
'class' => '\crestoff\badlogin\LoginAttemptBehavior',
'attempts' => 3,
'duration' => 300,
'durationUnit' => 'second',
'disableDuration' => 900,
'clearOnHandle' => true,
'clearDuration' => 30,
'clearDurationUnit' => 'day',
'disableDurationUnit' => 'second',
'usernameAttribute' => 'email',
'passwordAttribute' => 'password',
'message' => 'Login is disabled',
];
return $behaviors;
}