diff --git a/features/LimitRetry.php b/features/LimitRetry.php index 25aaf27..8705f2c 100644 --- a/features/LimitRetry.php +++ b/features/LimitRetry.php @@ -22,8 +22,10 @@ use APP\plugins\generic\betterPassword\handlers\DisabledLoginHandler; use PKP\core\PKPApplication; use PKP\db\DAORegistry; +use PKP\facades\Locale; use PKP\plugins\Hook; use PKP\security\Validation; +use Carbon\CarbonInterval; class LimitRetry { @@ -83,15 +85,24 @@ private function _handleTemplateDisplay(): void // And the user is not currently locked if ($user->getCount() < $this->_maxRetries || $user->getFailedTime() <= time() - $this->_lockSeconds) { $badpwFailedLoginsDao->resetCount($user); + // Update the local counter + $count = 0; } } // Update the count to represent this failed attempt $badpwFailedLoginsDao->incCount($user); + // Update the local counter + $count ++; // Warn the user if the attempts have been exhausted if ($count >= $this->_maxRetries) { + $label = CarbonInterval::seconds(max($this->_lockExpiresSeconds, $this->_lockSeconds)) + ->cascade() + ->locale(Locale::getLocale()) + ->forHumans(['parts' => 2, 'short' => false]); $templateManager->assign('error', 'plugins.generic.betterPassword.validation.betterPasswordLocked'); + $templateManager->assign('reason', $label); } }); } diff --git a/locale/en/locale.po b/locale/en/locale.po index a763ea3..40dbbf3 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -36,7 +36,7 @@ msgid "plugins.generic.betterPassword.validation.betterPasswordCheckBlocklist" msgstr "Your password was found in a blocklist of known bad passwords." msgid "plugins.generic.betterPassword.validation.betterPasswordLocked" -msgstr "Your account has been temporarily locked due to bad password attempts." +msgstr "Your account has been temporarily locked due to bad password attempts. It will unlock automatically within {$reason}. For immediate access, use the \"Forgot your password?\" link to reset your password." msgid "plugins.generic.betterPassword.validation.betterPasswordUnexpectedError" msgstr "Your password could not be changed at this time. Please try again later."