Skip to content

Commit

Permalink
fix: for issue #581
Browse files Browse the repository at this point in the history
  • Loading branch information
David McReynolds committed Aug 9, 2021
1 parent 8a0d88a commit 15934fd
Showing 1 changed file with 54 additions and 27 deletions.
81 changes: 54 additions & 27 deletions fuel/modules/fuel/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,8 @@ public function index()
}
else
{
// check if they are no longer in the locked out state and reset variables
if (isset($user_data['failed_login_timer']) AND (time() - $user_data['failed_login_timer']) > (int)$this->fuel->config('seconds_to_unlock'))
{
$user_data['failed_login_attempts'] = 0;
$this->session->unset_userdata('failed_login_timer');
unset($user_data['failed_login_timer']);
}
else
{
// add to the number of attempts if it's an invalid login'
$num_attempts = (!isset($user_data['failed_login_attempts'])) ? 0 : $user_data['failed_login_attempts'] + 1;
$user_data['failed_login_attempts'] = $num_attempts;
}
$this->check_login_attempts($user_data, 'username');

// check if they should be locked out
if (isset($user_data['failed_login_attempts']) AND $user_data['failed_login_attempts'] >= (int)$this->fuel->config('num_logins_before_lock') -1)
{
$this->fuel_users_model->add_error(lang('error_max_attempts', $this->fuel->config('seconds_to_unlock')));
$user_data['failed_login_timer'] = time();
$this->fuel->logs->write(lang('auth_log_account_lockout', $this->input->post('user_name', TRUE), $this->input->ip_address()), 'debug');
}
else
{
$this->fuel_users_model->add_error(lang('error_invalid_login'));
$this->fuel->logs->write(lang('auth_log_failed_login', $this->input->post('user_name', TRUE), $this->input->ip_address(), ($user_data['failed_login_attempts'] + 1)), 'debug');
}
}
}
else
Expand Down Expand Up @@ -188,14 +164,26 @@ public function pwd_reset()

$this->js_controller_params['method'] = 'add_edit';

$session_key = $this->fuel->auth->get_session_namespace();

$user_data = $this->session->userdata($session_key);

if ( ! empty($_POST))
{
if ($this->input->post('email'))
if (isset($user_data['failed_login_timer']) AND (time() - $user_data['failed_login_timer']) < (int)$this->fuel->config('seconds_to_unlock'))
{
$this->fuel_users_model->add_error(lang('error_max_attempts', $this->fuel->config('seconds_to_unlock')));
$user_data['failed_login_timer'] = time();
}
elseif ($this->input->post('email'))
{
$user = $this->fuel_users_model->find_one_array(array('email' => $this->input->post('email')));

if ( ! empty($user['email']))
{
// reset failed login attempts
$user_data['failed_login_timer'] = 0;

// This generates and saves a token to the user model, returns the token string.
$token = $this->fuel_users_model->get_reset_password_token($user['email']);

Expand Down Expand Up @@ -231,8 +219,10 @@ public function pwd_reset()
}
else
{
$this->fuel_users_model->add_error(lang('error_invalid_email'));
$this->check_login_attempts($user_data, 'email');
}

$this->session->set_userdata($session_key, $user_data);
}
else
{
Expand Down Expand Up @@ -260,6 +250,43 @@ public function pwd_reset()

}

protected function check_login_attempts(&$user_data, $field)
{
if (isset($user_data['failed_login_timer']) AND (time() - $user_data['failed_login_timer']) > (int)$this->fuel->config('seconds_to_unlock'))
{
$user_data['failed_login_attempts'] = 0;
$this->session->unset_userdata('failed_login_timer');
unset($user_data['failed_login_timer']);
}
else
{
// add to the number of attempts if it's an invalid login'
$num_attempts = (!isset($user_data['failed_login_attempts'])) ? 0 : $user_data['failed_login_attempts'] + 1;
$user_data['failed_login_attempts'] = $num_attempts;
}

// check if they should be locked out
if (isset($user_data['failed_login_attempts']) AND $user_data['failed_login_attempts'] >= (int)$this->fuel->config('num_logins_before_lock') -1)
{
$this->fuel_users_model->add_error(lang('error_max_attempts', $this->fuel->config('seconds_to_unlock')));
$user_data['failed_login_timer'] = time();
$this->fuel->logs->write(lang('auth_log_account_lockout', $this->input->post($field, TRUE), $this->input->ip_address()), 'debug');
}
else
{
if ($field == 'email')
{
$this->fuel_users_model->add_error(lang('error_invalid_email'));
$this->fuel->logs->write(lang('error_invalid_email', $this->input->post('email', TRUE), $this->input->ip_address(), ($user_data['failed_login_attempts'] + 1)), 'debug');
}
else
{
$this->fuel_users_model->add_error(lang('error_invalid_login'));
$this->fuel->logs->write(lang('auth_log_failed_login', $this->input->post('user_name', TRUE), $this->input->ip_address(), ($user_data['failed_login_attempts'] + 1)), 'debug');
}
}
}

// THIS HANDLES A POST REQUEST FOR USER SETTING A NEW PASSWORD
public function reset_password()
{
Expand Down

0 comments on commit 15934fd

Please sign in to comment.