-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotp.php
More file actions
157 lines (136 loc) · 3.05 KB
/
otp.php
File metadata and controls
157 lines (136 loc) · 3.05 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
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
<?php
session_start();
include "dbcon.php";
if (!isset($_SESSION["email"])) {
header("Location: register.php");
exit();
}
$email = $_SESSION["email"];
$error = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$otp = trim($_POST["otp"]);
if (!preg_match("/^\d{6}$/", $otp)) {
$error = "Enter a valid 6-digit OTP.";
} else {
$stmt = $conn->prepare("SELECT * FROM users WHERE email=? AND otp_code=?");
$stmt->bind_param("ss", $email, $otp);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows > 0) {
$row = $res->fetch_assoc();
$user_unique_id = $row['user_unique_id'];
// Clear OTP after successful verification
$update = $conn->prepare("UPDATE users SET otp_code=NULL WHERE email=?");
$update->bind_param("s", $email);
$update->execute();
$_SESSION["user_id"] = $user_unique_id;
$_SESSION["logged_in"] = true;
header("Location: home.php");
exit();
} else {
$error = "Incorrect OTP. Try again.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter OTP</title>
<style>
body {
font-family: Arial, sans-serif;
background: #a8d9d6;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.otp-container {
background: #74b5b4;
width: 80%;
max-width: 400px;
padding: 25px;
border-radius: 18px;
text-align: center;
box-shadow: 0px 4px 12px rgba(0,0,0,0.15);
}
h2 {
font-size: 28px;
margin-bottom: 10px;
color: #0f3f3f;
}
p {
font-size: 16px;
color: #0f3f3f;
margin-bottom: 20px;
}
input {
width: 80%;
padding: 14px;
font-size: 22px;
border-radius: 10px;
border: none;
outline: none;
text-align: center;
margin-bottom: 15px;
}
button {
width: 60%;
padding: 14px;
background: #1e3b36;
color: white;
border: none;
border-radius: 12px;
font-size: 20px;
cursor: pointer;
transition: 0.2s ease;
}
button:hover {
opacity: 0.9;
}
.error {
color: darkred;
font-size: 16px;
margin-bottom: 10px;
}
/* MOBILE OPTIMIZATION */
@media (max-width: 480px) {
h2 {
font-size: 24px;
}
.otp-container {
margin-top: -35%;
}
p {
font-size: 14px;
}
input {
font-size: 20px;
padding: 12px;
}
button {
font-size: 18px;
padding: 12px;
}
}
</style>
</head>
<body>
<div class="otp-container">
<h2>Enter OTP</h2>
<p>An OTP has been sent to <strong><?php echo htmlspecialchars($email); ?></strong></p>
<?php if ($error): ?>
<div class="error"><?= $error ?></div>
<?php endif; ?>
<form method="POST">
<input type="text" name="otp" placeholder="6-digit OTP" maxlength="6" required>
<button type="submit">Verify</button>
</form>
</div>
</body>
</html>