php - Throttling attempts not being recorded into database -
hi trying create login throttling object oriented php, have created structured code can not work object oriented far heres code:
public function find_failed_login($email = null) { if(!empty($email)) { $query = "select * {$this->table} email = '".$this->db->escape($email)."'"; return $this->db->query($query); } } public function record_failed_login($email) { $count = 1; $time = time(); $failed_login = $this->find_failed_login($email); if(!$failed_login) { $query = "insert {$this->table} (email, count, last_time) values ('".$this->db->escape($email)."', {$count}, {$time})"; return $this->db->query($query); } else { $query = "update {$this->table} set email = '{$email}', count = count + 1, last_time = {$time}"; return $this->db->query($query); } } public function clear_failed_logins($email = null) { if(!empty($email)) { $failed_login = $this->find_failed_login($email); if(isset($failed_login)) { $query = "delete {$this->table} email = '".$this->db->escape($email)."'"; return $this->db->query($query); } } } public function throttle_failed_logins($email = null) { if(!empty($email)) { $throttle_at = 3; $delay_in_minutes = 1; $delay = 60 * $delay_in_minutes; $failed_login = $this->find_failed_login($email); if(isset($failed_login)) { while($failed = mysqli_fetch_assoc($failed_login)) { if(isset($failed) && $failed['count'] >= $throttle_at) { $remaining_delay = ($failed['last_time'] + $delay) - time(); $remaining_delay_in_minutes = ceil($remaining_delay / 60); return $remaining_delay_in_minutes; } else { return 0; } } } } }
and in login page calling this:
$objlogin = new login(); if($objform->ispost('login_email')) { $throttle_delay = $objlogin->throttle_failed_logins($objform->getpost('login_email')); if($throttle_delay > 0) { $objvalid->add2errors('failed_logins'); }
when try no error or matter, dead code, appreciate professional :)
Comments
Post a Comment