-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewpassword.php
159 lines (142 loc) · 4.93 KB
/
newpassword.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
include("./php/database.php");
$response = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['password']) && isset($_POST['confirm_password'])) {
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$username = $_SESSION['user'];
// Check if passwords match
if ($password !== $confirm_password) {
$response = "Passwords do not match.";
} else {
// Validate password strength
if (strlen($password) < 8) {
$response = "Password should be at least 8 characters long.";
} elseif (!preg_match('/[A-Z]/', $password)) {
$response = "Password should contain at least one uppercase letter.";
} elseif (!preg_match('/[a-z]/', $password)) {
$response = "Password should contain at least one lowercase letter.";
} elseif (!preg_match('/\d/', $password)) {
$response = "Password should contain at least one number.";
} elseif (!preg_match('/[^a-zA-Z0-9]/', $password)) {
$response = "Password should contain at least one special character.";
} else {
// Hash the password
$password_hash = password_hash($password, PASSWORD_BCRYPT);
// Update password in the database
$sql = "UPDATE login SET Password='$password_hash' WHERE Email ='$username'";
$result = $conn->query($sql);
if ($result) {
$response = "Password updated successfully";
} else {
$response = "Unable to update password";
}
}
}
} else {
$response = "Invalid request.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Password</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
nav {
background-color: #333;
padding: 10px 0;
text-align: center;
}
nav a {
color: #fff;
margin: 0 10px;
text-decoration: none;
}
nav a:hover {
text-decoration: underline;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-form {
width: 300px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
input[type="password"] {
width: 100%;
padding: 10px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.response-message {
text-align: center;
margin-top: 10px;
color: red;
/* Default color for error messages */
}
.success {
color: green;
/* Color for success messages */
}
</style>
</head>
<body>
<nav>
<a href="index.php">Home</a>
<a href="about.php">About</a>
<a href="contact.php">Contact</a>
</nav>
<div class="container">
<div class="login-form">
<h2 style="text-align: center;">Enter New Password</h2>
<form method="post" action="">
<input type="password" id="password" name="password" placeholder="New Password" required>
<input type="password" id="confirm_password" name="confirm_password" placeholder="Confirm Password" required>
<input type="submit" value="Submit">
<div id="response-message" class="response-message"><?php echo $response; ?></div>
</form>
</div>
</div>
</body>
<script>
// Hide the response message after 5 seconds
setTimeout(function() {
var responseMessage = document.getElementById('response-message');
if (responseMessage.textContent.trim() === 'Password updated successfully') {
window.location.href = 'login.php';
} else {
responseMessage.style.display = 'none';
}
}, 1000);
</script>
</html>