added login rate limit

This commit is contained in:
lakshya chauhan
2022-07-21 17:08:13 +05:30
parent 617f04c975
commit 5fb51e7692
2 changed files with 104 additions and 7 deletions

View File

@@ -249,10 +249,7 @@ class FrontControllerCore extends Controller
$this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
// Init cookie language
// @TODO This method must be moved into switchLanguage
Tools::setCookieLanguage($this->context->cookie);
$this->displayMaintenancePage();
// If current URL use SSL, set it true (used a lot for module redirect)
if (Tools::usingSecureMode()) {
@@ -277,6 +274,9 @@ class FrontControllerCore extends Controller
}
ob_start();
// Init cookie language
// @TODO This method must be moved into switchLanguage
$protocol_link = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
$useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
$protocol_content = ($useSSL) ? 'https://' : 'http://';
@@ -750,7 +750,7 @@ class FrontControllerCore extends Controller
*/
protected function displayMaintenancePage()
{
if (isset(Context::getContext()->cookie->remote_addr)
if (isset(Context::getContext()->cookie->remote_addr)
&& Context::getContext()->cookie->remote_addr != ip2long(Tools::getRemoteAddr())
) {
$cookie = Context::getContext()->cookie;
@@ -761,7 +761,7 @@ class FrontControllerCore extends Controller
}
}
if (Tools::isSubmit('SubmitLogin')
if (Tools::isSubmit('SubmitLogin')
&& Configuration::get('PS_ALLOW_EMP')
&& !Context::getContext()->cookie->enable_maintenance_view
) {
@@ -769,7 +769,7 @@ class FrontControllerCore extends Controller
$passwd = trim(Tools::getValue('passwd'));
$this->processLogin($email, $passwd);
}
if (!Context::getContext()->cookie->enable_maintenance_view || !Configuration::get('PS_ALLOW_EMP')) {
Context::getContext()->cookie->__unset('enable_maintenance_view');
Context::getContext()->cookie->write();
@@ -777,7 +777,7 @@ class FrontControllerCore extends Controller
$this->maintenance = true;
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) {
header('HTTP/1.1 503 temporarily overloaded');
$this->context->smarty->assign($this->initLogoAndFavicon());
$this->context->smarty->assign(array(
'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()),
@@ -796,6 +796,8 @@ class FrontControllerCore extends Controller
protected function processLogin($email, $passwd)
{
$result = false;
$objLoginFail = new LoginFail;
/* Check fields validity */
if (empty($email)) {
$this->errors[] = Tools::displayError('Email is empty.');
@@ -809,6 +811,10 @@ class FrontControllerCore extends Controller
$this->errors[] = Tools::displayError('Invalid password.');
}
if ($objLoginFail->checkLimit($email)) {
$this->errors[] =Tools::displayError('You have exceeded the limit of login attempts, please try after some time');
}
if (!count($this->errors)) {
// Find employee
$this->context->employee = new Employee();
@@ -829,6 +835,10 @@ class FrontControllerCore extends Controller
}
if (count($this->errors)) {
$this->context->smarty->assign('errors', $this->errors);
$objLoginFail->email = $email;
$objLoginFail->ip_address = Tools::getRemoteAddr();
$objLoginFail->save();
$objLoginFail->cleanData();
} else {
Tools::redirect('index.php');
}