/** * Submission of Change Password form */ public function change_password() { $form_url = 'account'; if (validate_form($form_url)) { // update db $password = $this->input->post('password'); $update_data = ['password' => hash_pw($password)]; $result = $this->backend_users->update($this->mUser['id'], $update_data); // success set_alert('success', 'Mot de passe changé.'); } // back to form redirect($form_url); }
<?php session_start(); include "config.php"; include "private_functions.php"; include "functions.php"; if (isset($_SESSION['auth']) && $_SESSION['auth'] == 1) { header('Location: ' . $home . 'index.php'); } if (isset($_POST['username']) && isset($_POST['pw'])) { $pw = hash_pw($_POST['pw']); $dbh = db_connect($MY_HOST, $MY_DB_PORT, $MY_DB, $DB_USER, $DB_PW); $res = login($dbh, $_POST['username'], $pw); error_log("In Error Log -----> test login"); if ($res['status'] == 1) { session_login($res['userID']); header("Location: " . $home . "index.php"); } else { $err_msg = "Invalid login"; } } ?> <html> <head> <title>Login</title> <?php html_output_head(); ?> </head> <body> <div class="container">
public function change_password() { if (validate_form('account')) { // check if current password match the record $user = $this->users->get($this->mUser['id']); $current_password = $this->input->post('current_password'); if (verify_pw($current_password, $user['password'])) { // change user password $new_password = $this->input->post('new_password'); $success = $this->users->update($this->mUser['id'], array('password' => hash_pw($new_password))); // (optional) send Password Changed email //$to_name = $user['first_name'].' '.$user['last_name']; //$subject = 'Password Changed'; //send_email($user['email'], $to_name, $subject, 'password_changed', $user); if ($success) { set_alert('success', 'Password changed successfully.'); } else { set_alert('danger', 'Database error.'); } } else { set_alert('danger', 'Incorrect current password.'); } } redirect('account'); }
/** * Grocery Crud callback functions */ public function callback_before_create_user($post_array) { $post_array['password'] = hash_pw($post_array['password']); return $post_array; }
<?php session_start(); include "../config.php"; include "../functions.php"; include "../private_functions.php"; if (isset($_GET['username']) && isset($_GET['pw'])) { $pw = hash_pw($_GET['pw']); $dbh = db_connect($MY_HOST, $MY_DB_PORT, $MY_DB, $DB_USER, $DB_PW); $res = login($dbh, $_GET['username'], $pw); close_db_connection($dbh); if ($res['status'] == 1) { session_login($res['userID']); } echo json_encode($res); } else { echo json_encode(array("status" => 0)); }