1. Go to this page and download the library: Download ognyk/yii2-login-blocker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/* Check if user can login */
\Yii::$app->loginBlocker->check();
/* Increment counter when wrong login or password */
\Yii::$app->loginBlocker->block();
if (!\Yii::$app->loginBlocker->check()) {
return ['error' => 'time_block'];
}
if ($model->login()) {
// ... good action here
} else {
\Yii::$app->loginBlocker->block();
return ['error' => 'wrong_credentials'];
}
'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)
]
]