Skip to content

Commit

Permalink
added totp_only_on_ip_change
Browse files Browse the repository at this point in the history
  • Loading branch information
REJack committed May 26, 2015
1 parent d2cf407 commit f4c42a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion application/config/aauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
$config['aauth']['recaptcha_secret'] = '';

$config['aauth']['totp_active'] = false;
$config['aauth']['totp_only_on_ip_change'] = false;
$config['aauth']['totp_reset_over_reset_password'] = false;

// login attempts time interval
// default 20 times in one hour
$config['aauth']['max_login_attempt'] = 10;
Expand Down
28 changes: 27 additions & 1 deletion application/libraries/Aauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function login($identifier, $pass, $remember = FALSE, $totp_code = NULL)
}
}

if($this->config_vars['totp_active'] == TRUE){
if($this->config_vars['totp_active'] == TRUE AND $this->config_vars['totp_only_on_ip_change'] == FALSE){
$query = null;
$query = $this->aauth_db->where($db_identifier, $identifier);
$query = $this->aauth_db->get($this->config_vars['users']);
Expand All @@ -255,6 +255,32 @@ public function login($identifier, $pass, $remember = FALSE, $totp_code = NULL)
}
}
}

if($this->config_vars['totp_active'] == TRUE AND $this->config_vars['totp_only_on_ip_change'] == TRUE){
$query = null;
$query = $this->aauth_db->where($db_identifier, $identifier);
$query = $this->aauth_db->get($this->config_vars['users']);
$totp_secret = $query->row()->totp_secret;
$ip_address = $query->row()->ip_address;
$current_ip_address = $this->CI->input->ip_address();
if ($query->num_rows() > 0 AND !$totp_code) {
if($ip_address != $current_ip_address ){
$this->error($this->CI->lang->line('aauth_error_totp_code_required'));
return FALSE;
}
}else {
if(!empty($totp_secret)){
if($ip_address != $current_ip_address ){
$ga = new PHPGangsta_GoogleAuthenticator();
$checkResult = $ga->verifyCode($totp_secret, $totp_code, 0);
if (!$checkResult) {
$this->error($this->CI->lang->line('aauth_error_totp_code_invalid'));
return FALSE;
}
}
}
}
}

// if email and pass matches and not banned
if ( $query->num_rows() > 0 ) {
Expand Down

0 comments on commit f4c42a3

Please sign in to comment.