changed table name LoginFail to MaintenanceAccess
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
* @license https://store.webkul.com/license.html
|
||||
*/
|
||||
|
||||
class LoginFailCore extends ObjectModel
|
||||
class MaintenanceAccessCore extends ObjectModel
|
||||
{
|
||||
|
||||
public $id_login_fail;
|
||||
public $id_maintenance_access;
|
||||
public $ip_address;
|
||||
public $email;
|
||||
public $created_at;
|
||||
public $date_add;
|
||||
const USERNAME_ATTEMPTS_PER_QUARTER_HOUR = 3;
|
||||
const IP_ATTEMPTS_QUARTER_HOUR = 12;
|
||||
const USERNAME_ATTEMPTS_PER_HOUR = 6;
|
||||
@@ -37,11 +37,12 @@ class LoginFailCore extends ObjectModel
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'login_fail',
|
||||
'primary' => 'id_login_fail',
|
||||
'table' => 'maintenance_access',
|
||||
'primary' => 'id_maintenance_access',
|
||||
'fields' => array(
|
||||
'ip_address' => array('type' => self::TYPE_STRING, 'size' => 50),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -49,15 +50,14 @@ class LoginFailCore extends ObjectModel
|
||||
{
|
||||
$time = (time() - (self::HOUR*2));
|
||||
Db::getInstance()->execute(
|
||||
'
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'login_fail`
|
||||
WHERE `created_at` < "' . pSQL(date("Y-m-d H:i:s", $time)) . '"'
|
||||
'DELETE FROM `' . _DB_PREFIX_ .'maintenance_access`
|
||||
WHERE `date_add` < "' . pSQL(date("Y-m-d H:i:s", $time)) . '"'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUserFailedCount($time, $email=false, $ip_address=false, $attempts)
|
||||
{
|
||||
$sql = "SELECT COUNT(id_login_fail) FROM `". _DB_PREFIX_ ."login_fail` WHERE `created_at` > '"
|
||||
$sql = "SELECT COUNT(`id_maintenance_access`) FROM `". _DB_PREFIX_ ."maintenance_access` WHERE `date_add` > '"
|
||||
. pSQL(date('Y-m-d H:i:s', $time)) ."'";
|
||||
|
||||
if ($email) {
|
||||
@@ -67,6 +67,7 @@ class LoginFailCore extends ObjectModel
|
||||
if ($ip_address) {
|
||||
$sql .= " AND `ip_address` = '".pSQL($ip_address)."'";
|
||||
}
|
||||
|
||||
return Db::getInstance()->getValue($sql) >= $attempts;
|
||||
}
|
||||
|
||||
@@ -77,10 +78,18 @@ class LoginFailCore extends ObjectModel
|
||||
$hours_ago = time() - self::HOUR;
|
||||
$ip_address = Tools::getRemoteAddr();
|
||||
|
||||
$has_error |= $this->getUserFailedCount($minutes_ago, $email, false, self::USERNAME_ATTEMPTS_PER_QUARTER_HOUR)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount($minutes_ago, false, $ip_address, self::IP_ATTEMPTS_QUARTER_HOUR)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount($hours_ago, $email, false, self::USERNAME_ATTEMPTS_PER_HOUR)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount($hours_ago, false, $ip_address, self::IP_ATTEMPTS_PER_HOUR)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount(
|
||||
$minutes_ago, $email, false, self::USERNAME_ATTEMPTS_PER_QUARTER_HOUR
|
||||
)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount(
|
||||
$minutes_ago, false, $ip_address, self::IP_ATTEMPTS_QUARTER_HOUR
|
||||
)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount(
|
||||
$hours_ago, $email, false, self::USERNAME_ATTEMPTS_PER_HOUR
|
||||
)? true : $has_error;
|
||||
$has_error |= $this->getUserFailedCount(
|
||||
$hours_ago, false, $ip_address, self::IP_ATTEMPTS_PER_HOUR
|
||||
)? true : $has_error;
|
||||
|
||||
return $has_error;
|
||||
}
|
||||
@@ -796,7 +796,7 @@ class FrontControllerCore extends Controller
|
||||
protected function processLogin($email, $passwd)
|
||||
{
|
||||
$result = false;
|
||||
$objLoginFail = new LoginFail;
|
||||
$objMaintenanceAccess = new MaintenanceAccess();
|
||||
|
||||
/* Check fields validity */
|
||||
if (empty($email)) {
|
||||
@@ -811,7 +811,7 @@ class FrontControllerCore extends Controller
|
||||
$this->errors[] = Tools::displayError('Invalid password.');
|
||||
}
|
||||
|
||||
if ($objLoginFail->checkLimit($email)) {
|
||||
if ($objMaintenanceAccess->checkLimit($email)) {
|
||||
$this->errors[] =Tools::displayError('You have exceeded the limit of login attempts, please try after some time');
|
||||
}
|
||||
|
||||
@@ -835,10 +835,9 @@ 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();
|
||||
$objMaintenanceAccess->email = $email;
|
||||
$objMaintenanceAccess->ip_address = Tools::getRemoteAddr();
|
||||
$objMaintenanceAccess->save();
|
||||
} else {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
@@ -2688,10 +2688,10 @@ CREATE TABLE IF NOT EXISTS `PREFIX_cms_role_lang` (
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_login_fail` (
|
||||
`id_login_fail` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_maintenance_access` (
|
||||
`id_maintenance_access` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`ip_address` varchar(50) NOT NULL,
|
||||
`email` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id_login_fail`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
`date_add` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_maintenance_access`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
Reference in New Issue
Block a user