Viewing file: change_pass_adm.php (4.31 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include('conn.php');
session_start();
if (isset($_POST['change_pass'])) {
$adm_id = $_SESSION['adm_id'];
$current_password = mysqli_real_escape_string($con, $_POST['current_password']);
$new_password = mysqli_real_escape_string($con, $_POST['new_password']);
$confirm_password = mysqli_real_escape_string($con, $_POST['confirm_password']);
// Fetch the hashed password from the database based on the admin ID
$query = mysqli_query($con, "SELECT adm_password FROM admission WHERE adm_id = '$adm_id'");
$check_fetch = mysqli_fetch_assoc($query);
if ($check_fetch) {
$storedHashedPassword = $check_fetch['adm_password'];
// Verify the current password using password_verify()
if (password_verify($current_password, $storedHashedPassword)) {
if ($new_password === $confirm_password) {
// Hash the new password
$hashedPassword = password_hash($new_password, PASSWORD_DEFAULT);
// Update the password in the database
$update_query = mysqli_query($con, "UPDATE admission SET adm_password = '$hashedPassword' WHERE adm_id = '$adm_id'");
if ($update_query) {
echo "Password changed successfully.";
} else {
echo "Error changing password. Please try again.";
}
} else {
echo "New password and confirm password do not match.";
}
} else {
echo "Incorrect current password.";
}
} else {
echo "Error retrieving password information.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link href="css/admin-css/style.css" rel="stylesheet" />
<link href="css/admin-css/font-awesome.css" rel="stylesheet" />
<title><?php include('title.php') ?></title>
<!-- Meta-Tags -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta name="keywords" content="Change Password Form">
<style>
body {
background-image: url('../assets/img/hero-slider/slider-1.jpg');
background-size: cover;
}
.background-overlay {
background-color: rgba(0, 0, 0, 0.4);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
</style>
<script>
addEventListener("load", function () {
setTimeout(hideURLbar, 0);
}, false);
function hideURLbar() {
window.scrollTo(0, 1);
}
</script>
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese" rel="stylesheet">
</head>
<body>
<div class="background-overlay"></div>
<div>
<h1>Kateb Hospital Admission Panel</h1>
<!--728x90-->
<div class="clear-loading spinner">
<span></span>
</div>
<!--728x90-->
<div class="w3ls-login box box--big">
<!-- form starts here -->
<form method="post">
<div class="agile-field-txt">
<label style="color: white; font-weight: bold;"> Current Password </label>
<input type="password" name="current_password" placeholder="Enter Current Password" required="" />
</div>
<div class="agile-field-txt">
<label style="color: white; font-weight: bold;"> New Password </label>
<input type="password" name="new_password" placeholder="Enter New Password" required="" />
</div>
<div class="agile-field-txt">
<label style="color: white; font-weight: bold;">Confirm Password </label>
<input type="password" name="confirm_password" placeholder="Confirm New Password" required="" />
</div>
<input type="submit" name="change_pass" value="CHANGE PASSWORD">
<a href="admission-login.php" style="color: white; font-size: 20px;">Back To Login </a>
</form>
</div>
</div>
</body>
</html>
|