0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
ACCOUNTS
/
[
Home
]
File: changepassword_ctrl.php
<?php require_once "../lib/config.php"; require_once "../model/employee_mdl.php"; require_once BASE_DIR."/lib/db/connection.php"; use YourNamespace\Connection; // Adjust the namespace as needed $ex_password = ""; $newpassword = ""; $confirmpassword = ""; $error_flag = 0; $ex_password = @$_POST['txtex_password']; $newpassword = @$_POST['txtnewpassword']; $confirmpassword = @$_POST['txtconfirmpassword']; $user_id = @$_SESSION['user_id']; $mysqli = new mysqli("localhost", "root", "", "cpms"); if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } if ($ex_password == "") { $error['password_null'] = "Please Enter Existing password"; $error_flag = 1; } if ($newpassword == "") { $error['newpassword_null'] = "Please Enter newpassword"; $error_flag = 1; } if ($confirmpassword == "") { $error['confirmpassword_null'] = "Please Enter confirmpassword"; $error_flag = 1; } if ($confirmpassword != $newpassword) { $error['confirm_null'] = "Password mismatch"; $error_flag = 1; } $mysqli = new mysqli("localhost", "root", "", "cpms"); if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } $sql = "SELECT * FROM `user` WHERE `user_id` = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $user_id); try { $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); if (!$row || $row['passwd'] != $ex_password) { $error['password_null'] = "Invalid password"; $error_flag = 1; } } catch (Exception $e) { // Handle database error if needed } $stmt->close(); if ($error_flag == 1) { include("changepassword.php"); exit(); } else try { $sql = "UPDATE `user` SET `passwd` = ? WHERE `user_id` = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('ss', $newpassword, $user_id); $stmt->execute(); $test = $stmt->affected_rows; if ($test > 0) { $message = "Password updated"; @$_SESSION['password'] = $newpassword; $url = $server_ip . "accounts/changepassword.php?message=$message"; echo "<script>window.location='$url'</script>"; exit(); } else { $message = "Not set"; $url = $server_ip . "accounts/changepassword.php?message=$message"; echo "<script>window.location='$url'</script>"; exit(); } } catch (Exception $e) { // Handle database error if needed } $stmt->close(); ?>