Skip to content

Commit

Permalink
forbid password reset when token has expired
Browse files Browse the repository at this point in the history
  • Loading branch information
tenzap committed Dec 20, 2024
1 parent a14efd9 commit 93b5425
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
33 changes: 21 additions & 12 deletions application/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,37 @@ function password_reset($token = NULL)
{
$this->load->helper('form');

if ($_POST && empty($this->input->post('change_language')))
$password_submitted = ($_POST && empty($this->input->post('change_language')));

if ($password_submitted)
{
$token = $this->input->post('token');
$user_token = $this->Kalkun_model->valid_token($token);
$this->Kalkun_model->update_password($user_token['id_user']);
$this->Kalkun_model->delete_token($user_token['id_user']);
$this->session->set_flashdata('errorlogin', tr_raw('Password changed successfully.'));
redirect('login?l='.$this->idiom);
}

if ( ! $this->Kalkun_model->valid_token($token))
$user_token = $this->Kalkun_model->valid_token($token);

if ($user_token === FALSE)
{
$this->session->set_flashdata('errorlogin', tr_raw('Token invalid.'));
redirect('login/forgot_password?l='.$this->idiom);
}
else
{
$data['token'] = $token;
$data['idiom'] = $this->idiom;
$data['language_list'] = $this->lang->kalkun_supported_languages();
$data['idiom'] = $this->idiom;
$this->load->view('main/password_reset', $data);
if ($password_submitted)
{
$this->Kalkun_model->update_password($user_token['id_user']);
$this->Kalkun_model->delete_token($user_token['id_user']);
$this->session->set_flashdata('errorlogin', tr_raw('Password changed successfully.'));
redirect('login?l='.$this->idiom);
}
else
{
$data['token'] = $token;
$data['idiom'] = $this->idiom;
$data['language_list'] = $this->lang->kalkun_supported_languages();
$data['idiom'] = $this->idiom;
$this->load->view('main/password_reset', $data);
}
}
}
}
20 changes: 13 additions & 7 deletions application/models/Kalkun_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,22 @@ function valid_token($token = NULL)
{
$this->db->from('user_forgot_password');
$this->db->where('token', $token);
$token = $this->db->get();
$token_result = $this->db->get();

if ($token->num_rows() === 1)
if ($token_result->num_rows() === 1)
{
return $token->row_array();
}
else
{
return FALSE;
if (strtotime('now') < strtotime($token_result->row('valid_until')))
{
return $token_result->row_array();
}
else
{
$this->db->from('user_forgot_password');
$this->db->where('token', $token);
$this->db->delete();
}
}
return FALSE;
}

// --------------------------------------------------------------------
Expand Down

0 comments on commit 93b5425

Please sign in to comment.