-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.php
More file actions
95 lines (88 loc) · 3.36 KB
/
change_password.php
File metadata and controls
95 lines (88 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
session_start();
include("config.php");
if (!isset($_SESSION['user_id'])) {
echo "Access denied.";
exit;
}
$user_id=$_SESSION["user_id"];
$current_password = $_POST['current_password'];
$new_password = password_hash($_POST['new_password'], PASSWORD_DEFAULT);
$sql="SELECT * FROM users WHERE id='$user_id'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
$user = mysqli_fetch_assoc($result);
if(password_verify($current_password, $user["password"])){
$update="UPDATE users SET password='$new_password' WHERE id='$user_id'";
mysqli_query($conn, $update);}
}
mysqli_close($conn );
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Profile Updated - Honey E-Commerce</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
}
.container {
margin-top: 50px;
}
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">Honey E-Commerce</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarNav" aria-controls="navbarNav"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="profile.php">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="products.php">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout (<?php echo htmlspecialchars($_SESSION['name']); ?>)</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Main Container -->
<div class="container">
<?php if($result): ?>
<div class="alert alert-success text-center" role="alert">
<h4 class="alert-heading">Password Changed Successfully!</h4>
<p>Your profile has been updated.</p>
<hr>
<p class="mb-0">
<a href="profile.php" class="btn btn-warning">Go to Your Profile</a>
<a href="products.php" class="btn btn-secondary">Continue Shopping</a>
</p>
</div>
<?php else: ?>
<div class="alert alert-danger text-center" role="alert">
<h4 class="alert-heading">Error</h4>
<p>There was an error changing your password. Please try again later.</p>
<hr>
<p class="mb-0">
<a href="profile.php" class="btn btn-warning">Back to Profile</a>
</p>
</div>
<?php endif; ?>
</div>
<!-- Bootstrap JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>