forked from aadarshsenapati/Cartify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_password.php
More file actions
93 lines (82 loc) · 3.42 KB
/
Copy pathreset_password.php
File metadata and controls
93 lines (82 loc) · 3.42 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
<?php
include("includes/connection.php");
if (!isset($_SESSION['reset_email'], $_SESSION['reset_otp'])) {
header("Location: forgot_password.php");
exit();
}
$email = $_SESSION['reset_email'];
$msg = "";
if (isset($_POST['reset'])) {
$new_password = $_POST['password'];
$entered_otp = $_POST['otp'];
$actual_otp = $_SESSION['reset_otp'];
if ($entered_otp == $actual_otp) {
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
$sql = "UPDATE `users` SET `password`= ? WHERE `email`= ?;";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "ss", $hashed_password, $email);
if (mysqli_stmt_execute($stmt)) {
$msg = "Password updated successfully. <a href='user_login.php'>Login here</a>.";
} else {
$msg = "Something went wrong. Please try again.";
}
mysqli_stmt_close($stmt);
} else {
$msg = "Invalid OTP. Please check and try again.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Reset Password</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:[email protected]&family=Dosis:[email protected]&family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Inspiration&family=Italiana&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Playwrite+IN:[email protected]&family=Poiret+One&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Rubik';
background:rgba(202, 144, 134, 0.7);
}
.card {
margin-top: 70px;
background-color: rgba(202, 93, 74, 0.4);
padding:20px;
}
.alert {
margin-bottom: 20px;
}
.container {
border: none !important;
}
</style>
</head>
<body>
<?php include("includes/header.php"); ?>
<div class="container mt-5">
<div class="card mx-auto" style="max-width: 400px;">
<div class="card-body">
<h3 class="text-center">Reset Password</h3>
<p class="text-center text-muted">An OTP has been sent to <strong><?= htmlspecialchars($_SESSION['reset_email']) ?></strong></p>
<?php if ($msg): ?>
<div class="alert alert-info"><?= $msg ?></div>
<?php endif; ?>
<form method="post">
<div class="mb-3">
<label>Enter OTP</label>
<input type="number" name="otp" class="form-control" required placeholder="Enter 6-digit OTP">
</div>
<div class="mb-3">
<label>New Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<div class="d-grid">
<button type="submit" name="reset" class="btn" style="background-color:rgba(202, 93, 74, 0.7)">Reset Password</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>