Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// ※ 下記の例は、10分間に5回以上ログイン失敗したらログインを制限する
'LimitCount' => 5, // ログイン失敗の回数
'LimitTime' => 10, // チェックする時間(分)
// チェックをセッションキーではなくユーザーエージェントで判定する場合trueにする
'user_agent_check' => false,
];

/**
Expand Down
19 changes: 13 additions & 6 deletions Event/BcLimitLoginControllerEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ public function usersBeforeLogin(CakeEvent $event) {
// ログイン履歴を取得
$limitCount = Configure::read('BcLimitLogin.LimitCount');
$limitTime = (int) Configure::read('BcLimitLogin.LimitTime');
$conditions = [
'key' => $key, //デフォルトはセッションキーで判定
'ip_address' => $ipAddress,
'login_status' => 0,
'modified >=' => date('Y-m-d H:i:s', strtotime(($limitTime * -1) . ' minutes')),
];
// ユーザーエージェントチェック
$userAgent = Configure::read('BcLimitLogin.user_agent_check');
if (!empty($userAgent)) {
$conditions['user_agent'] = $data['BcLimitLogin']['user_agent'];
unset($conditions['key']);
}
$count = $this->BcLimitLogin->find('count', [
'conditions' => [
'key' => $key,
'ip_address' => $ipAddress,
'login_status' => 0,
'modified >=' => date('Y-m-d H:i:s', strtotime(($limitTime * -1) . ' minutes')),
],
'conditions' => $conditions,
'recursive' => -1,
'cache' => false,
]);
Expand Down