-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-password.php
107 lines (96 loc) · 4.49 KB
/
change-password.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
<?php
session_start();
require 'components/connection.php';
$message = "";
if (isset($_GET['reset'])) {
// Check if there is a user with the provided reset code
if (mysqli_num_rows(mysqli_query($conn, "SELECT * FROM users WHERE code='{$_GET['reset']}'")) > 0) {
// Check if the form to change the password has been submitted
if (isset($_POST['change'])) {
$password = mysqli_real_escape_string($conn, md5($_POST['password']));
$confirm_password = mysqli_real_escape_string($conn, md5($_POST['confirm-password']));
// Check if the new password matches the confirmed password
if ($password === $confirm_password) {
// Update the user's password and clear the reset code
$query = mysqli_query($conn, "UPDATE users SET password='{$password}', code='' WHERE code='{$_GET['reset']}'");
if ($query) {
header("Location: login.php");
}
} else {
// Display an error message if the passwords do not match
$message = "<div class='alert alert-danger'>Password do not match !</div>";
echo "<script>
setTimeout(function() {
var messageElement = document.querySelector('.alert-danger');
if (messageElement) {
messageElement.style.display = 'none';
}
}, 10000);
</script>";
}
}
} else {
// Display an error message if the reset link does not match any user
$message = "<div class='alert alert-danger'>Reset Link do not match !</div>";
echo "<script>
setTimeout(function() {
var messageElement = document.querySelector('.alert-danger');
if (messageElement) {
messageElement.style.display = 'none';
}
}, 10000);
</script>";
}
} else {
// Redirect to the forgot password page if the reset parameter is not set
header("Location: forgot-password.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Password</title>
<link rel="stylesheet" href="styles/forms.css" type="text/css" media="all" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<script src="https://kit.fontawesome.com/af562a2a63.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
</head>
<body>
<section class="form-section | padding-block-80">
<div class="grid-container">
<!-- Change password form -->
<div class="form-logo">
<a href="./" class="transition logo">
<i class="fa-solid fa-burger fa-2xl" style="color: #f1a409;"></i>
<span class="fw-black">BURPGER</span>
</a>
</div>
<div class="form-content | flow">
<h2 class="fs-third-heading fw-semi-bold">Change Password</h2>
<?php echo $message; ?>
<form action="" method="post">
<div class="inputs">
<label class="fw-medium" for="password">Password</label>
<input type="password" class="password" name="password" placeholder="6 or more characters" required>
</div>
<div class="inputs">
<label class="fw-medium" for="confirm-password">Confirm Password</label>
<input type="password" class="confirm-password" name="confirm-password" placeholder="Repeat password" required>
</div>
<button name="change" class="btn transition primary-btn" type="submit">Change Password</button>
</form>
<p>Back to <a class="transition fw-medium" href="index.php">Login</a></p>
</div>
<!-- End of form -->
</div>
</section>
<script>
$(document).ready(function() {
$('[title="Hosted on free web hosting 000webhost.com. Host your own website for FREE."]').hide();
});
</script>
</body>
</html>