-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-password.php
79 lines (66 loc) · 3.01 KB
/
reset-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
<?php
require_once "config.php";
$new_password = $confirm_password = "";
$new_password_err = $confirm_password_err = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty(trim($_POST["new_password"]))) {
$new_password_err = "Please enter the new password.";
} elseif (strlen(trim($_POST["new_password"])) < 6) {
$new_password_err = "Password must have atleast 6 characters.";
} else {
$new_password = trim($_POST["new_password"]);
}
if (empty(trim($_POST["confirm_password"]))) {
$confirm_password_err = "Please confirm the password.";
} else {
$confirm_password = trim($_POST["confirm_password"]);
if (empty($new_password_err) && ($new_password != $confirm_password)) {
$confirm_password_err = "Password did not match.";
}
}
if (empty($new_password_err) && empty($confirm_password_err)) {
$sql = "UPDATE users SET password = ? WHERE id = ?";
if ($stmt = mysqli_prepare($link, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_password, $param_id);
$param_password = password_hash($new_password, PASSWORD_DEFAULT);
$param_id = $_SESSION["id"];
if (mysqli_stmt_execute($stmt)) {
session_destroy();
header("location: sign-in.php");
exit();
} else {
echo "Oops! Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($link);
}
?>
<?php include 'topnav.php' ?>
<div class="container">
<div class="col-12 text-center">
<h2>Reset Password</h2>
<p>Please fill out this form to reset your password.</p>
<div class="col-12 d-flex justify-content-center">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group mb-2 col-auto">
<label>New Password</label>
<input type="password" name="new_password" class="form-control <?php echo (!empty($new_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $new_password; ?>">
<span class="invalid-feedback"><?php echo $new_password_err; ?></span>
</div>
<div class="form-group mb-2 col-auto">
<label>Confirm New Password</label>
<input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $confirm_password; ?>">
<span class="invalid-feedback"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group mb-2 col-auto">
<input type="submit" class="btn btn-black" value="Submit">
<input type="reset" class="btn btn-white ms-2" value="Reset">
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php' ?>