Welcome Guest, Not a member yet? Register   Sign In
ask forgot password use ion auth library
#1

[eluser]isran_85[/eluser]
I want to change forgot password function from twice(first email reset password and second email new password)step with one step,so when user input email addres it will be new password with reset password before.anyone can help me,
here is the code:
model:
Code:
public function forgotten_password($email = '')
{
     if (empty($email))
     {
  return FALSE;
     }

     $key = $this->hash_password(microtime().$email);

     $this->forgotten_password_code = $key;

     $this->db->where($this->ion_auth->_extra_where);

     $this->db->update($this->tables['users'], array('forgotten_password_code' => $key), array('email' => $email));

     return $this->db->affected_rows() == 1;
}

public function change_password($identity, $old, $new)
{
     $query = $this->db->select('password, salt')
         ->where($this->identity_column, $identity)
         ->where($this->ion_auth->_extra_where)
         ->limit(1)
         ->get($this->tables['users']);

     $result = $query->row();

     $db_password = $result->password;
     $old  = $this->hash_password_db($identity, $old);
     $new  = $this->hash_password($new, $result->salt);

     if ($db_password === $old)
     {
      //store the new password and reset the remember code so all remembered instances have to re-login
  $data = array(
       'password' => $new,
       'remember_code' => '',
        );

  $this->db->where($this->ion_auth->_extra_where);
  $this->db->update($this->tables['users'], $data, array($this->identity_column => $identity));

  return $this->db->affected_rows() == 1;
     }

     return FALSE;
}
controller:
Code:
function forgot_password()
{
  $this->form_validation->set_rules('email', 'Email Address', 'required');
  if ($this->form_validation->run() == false)
  {
   //setup the input
   $data['email'] = $this->input->post('email');
  
  
   //set any errors and display the form
   $data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
   $this->load->view('auth/forgot_password', $data);
  }
  else
  {
   //run the forgotten password method to email an activation code to the user
   $email = $this->input->post('email');
   $forgotten = $this->ion_auth->forgotten_passwd($email);
   $salt    =

   if ($forgotten)
   { //if there were no errors
    $this->session->set_flashdata('message', $this->ion_auth->messages());
    redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page
   }
   else
   {
    $this->session->set_flashdata('message', $this->ion_auth->errors());
    redirect("auth/forgot_password", 'refresh');
   }
  }
}

//reset password - final step for forgotten password
public function reset_password($code)
{
  $reset = $this->ion_auth->forgotten_passwd_complete($code);

  if ($reset)
  {  //if the reset worked then send them to the login page  
   $this->session->set_flashdata('message', $this->ion_auth->messages());
   redirect("auth/login", 'refresh');
  }
  else
  { //if the reset didnt work then send them back to the forgot password page
   $this->session->set_flashdata('message', $this->ion_auth->errors());
   redirect("auth/forgot_password", 'refresh');
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB