Skip to content

Commit

Permalink
Dev : use time() in failed_login-attempt => Calculate directly in sql…
Browse files Browse the repository at this point in the history
…, more compliant. ( datediff, time_to_sec aren(t OK in all SQL mode)

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11319 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shnoulle committed Nov 3, 2011
1 parent 3445cdc commit b947558
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions application/models/failed_login_attempts_model.php
Expand Up @@ -2,39 +2,38 @@

class Failed_login_attempts_model extends CI_Model {

function getAllRecords($condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}

$data = $this->db->get('failed_login_attempts');

return $data;
}

function getSomeRecords($fields,$condition=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
if ($condition != FALSE)
{
$this->db->where($condition);
}
function getAllRecords($condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}

$data = $this->db->get('failed_login_attempts');
$data = $this->db->get('failed_login_attempts');

return $data;
}
return $data;
}

function deleteAttempts($ip) {
function getSomeRecords($fields,$condition=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
if ($condition != FALSE)
{
$this->db->where($condition);
}

$data = $this->db->get('failed_login_attempts');

return $data;
}

$this->db->where('ip', $ip);
return $this->db->delete('failed_login_attempts');
}
function deleteAttempts($ip) {
$this->db->where('ip', $ip);
return $this->db->delete('failed_login_attempts');
}

/**
* Check if an IP address is allowed to login or not
Expand All @@ -45,7 +44,8 @@ function deleteAttempts($ip) {
function isLockedOut($sIPAddress)
{
$this->db->where('number_attempts >',$this->config->item("maxLoginAttempt"));
$this->db->where('ip >',$sIPAddress);
$this->db->where('ip =',$sIPAddress);
$this->db->where('last_attempt >',time()- $this->config->item("timeOutTime"));
$oQuery = $this->db->get('failed_login_attempts');
return ($oQuery->num_rows()>0);
}
Expand All @@ -56,27 +56,28 @@ function isLockedOut($sIPAddress)
*/
function cleanOutOldAttempts()
{
$this->db->where('((NOW() - CAST(last_attempt as DATETIME)) > '.$this->config->item("timeOutTime").')');

$this->db->where('(last_attempt <'.time()- $this->config->item("timeOutTime").')');
return $this->db->delete('failed_login_attempts');
}


function addAttempt($ip)
{

$timestamp = date("Y-m-d H:m:s");
function addAttempt($ip)
{
$timestamp = time();
$this->db->where('ip', $ip);
$oData=$this->db->get('failed_login_attempts');
if ($oData->num_rows()>0)
{
$query = $this->db->query("UPDATE ".$this->db->dbprefix('failed_login_attempts')
." SET number_attempts=number_attempts+1, last_attempt = '".$timestamp."' WHERE ip='".$ip."'");
}
else
$query = $this->db->query("INSERT INTO ".$this->db->dbprefix('failed_login_attempts') . "(ip, number_attempts,last_attempt)"
." VALUES('".$ip."',1,'".$timestamp."')");

return $query;
}
if ($oData->num_rows()>0)
{
$query = $this->db->query("UPDATE ".$this->db->dbprefix('failed_login_attempts')
." SET number_attempts=number_attempts+1, last_attempt = '".$timestamp."' WHERE ip='".$ip."'");
}
else
{
$query = $this->db->query("INSERT INTO ".$this->db->dbprefix('failed_login_attempts') . "(ip, number_attempts,last_attempt)"
." VALUES('".$ip."',1,'".$timestamp."')");

return $query;
}

}

0 comments on commit b947558

Please sign in to comment.