public function UserPasswordReset() { $key = $this->input->post('key', TRUE); $uId = $this->input->post('uId', TRUE); $npass = $this->input->post('npass', TRUE); $cpass = $this->input->post('cpass', TRUE); if (empty($key) || empty($uId) || empty($npass) || empty($cpass)) { $newdata = array('error' => "<font color='red'>unable to do this action.</font>"); $this->session->set_flashdata($newdata); redirect('/'); } else { if ($npass == $cpass) { $this->load->model('User_model'); $user = $this->User_model->getUserByKey($key); if (count($user) > 0) { $user = $user[0]; if ($key == $user->key) { $code = md5(time() . "aas^5s&dw#2" . rand()); $code = str_replace(array('/', '\\/'), '', Pass::hash($code)); $data['key'] = $code; $data['password'] = md5($npass); $ret = $this->User_model->updateUser($key, $data); if ($ret == 'SUCCESS') { $newdata = array('success' => "<font color='green'>Password has been reset successfully.</font>"); $this->session->set_flashdata($newdata); redirect('/'); } } else { $newdata = array('error' => "<font color='red'>Invalid key to reset password.</font>"); $this->session->set_flashdata($newdata); redirect('/'); } } else { $newdata = array('error' => "<font color='red'>User did not find.</font>"); $this->session->set_flashdata($newdata); redirect('/'); } } else { $newdata = array('error' => "<font color='red'>Confirm password did not match.</font>"); $this->session->set_flashdata($newdata); redirect('/'); } } }
public function changePassword() { if (Input::exists("opass") || Input::exists("npass") || Input::exists("cpass")) { $opass = Input::get("opass"); $npass = Input::get("npass"); $cpass = Input::get("cpass"); if (empty($opass) || empty($npass) || empty($cpass)) { textMsg("Required fields are empty.", "error"); Redirect::url("shippingUser/setting"); exit; } else { if ($npass == $cpass) { $user = User::find($_SESSION['userId']); $check = Pass::verify($user->password, $opass); if ($check) { $user->password = Pass::hash($npass); if ($user->save()) { textMsg("password has been updated.", "success"); Redirect::url("shippingUser/setting"); exit; } else { textMsg("Something went wrong try again.", "error"); Redirect::url("shippingUser/setting"); exit; } } else { textMsg("Old password did not match.", "error"); Redirect::url("shippingUser/setting"); exit; } } else { textMsg("Confirm password did not match.", "error"); Redirect::url("shippingUser/setting"); exit; } } } else { textMsg("Something went wrong try again.", "error"); Redirect::url("shippingUser/dashboard"); exit; } }
public function UserPasswordReset() { if (Input::exists("key") || Input::exists("uId") || Input::exists("autnKey") || Input::exists("npass") || Input::exists("cpass")) { $key = Input::get("key"); $uId = Input::get("uId"); $authKey = Input::get("autnKey"); $npass = Input::get("npass"); $cpass = Input::get("cpass"); if (empty($key) || empty($uId) || empty($authKey) || empty($npass) || empty($cpass)) { textMsg("unable to do this action.", "error"); Redirect::url("home/index"); exit; } else { if ($_SESSION['key'] == $authKey) { if ($npass == $cpass) { $user = User::all(['id' => $uId])[0]; if (count($user) > 0) { if ($key == $user->key) { $code = md5(time() . "aas^5s&dw#2" . rand()); $code = str_replace(array('/', '\\/'), '', Pass::hash($code)); $user->password = Pass::hash($npass); $user->key = $code; if ($user->save()) { textMsg("Password has been reset successfully.", "success"); Redirect::url("home/index"); exit; } } else { textMsg("Invalid key to reset password.", "error"); Redirect::url("home/index"); exit; } } else { textMsg("User did not find.", "error"); Redirect::url("home/index"); exit; } } else { textMsg("Confirm password did not match.", "error"); Redirect::url("home/index"); exit; } } else { textMsg("You are roobot.", "error"); Redirect::url("home/index"); exit; } } } }