-
Notifications
You must be signed in to change notification settings - Fork 0
/
otp_verification.php
85 lines (73 loc) · 2.83 KB
/
otp_verification.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
<?php
require_once "importance.php";
if (!User::loggedIn()) {
Config::redir("login.php");
}
$loggedInUserToken = User::getToken();
if (isset($_POST['verification_code'])) {
$enteredOTP = $_POST['verification_code'];
$host = "localhost";
$dbname = "ntsystem";
$username = "root";
$password = "";
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare and execute the SQL query to fetch OTP for the logged-in user
$stmt = $pdo->prepare("SELECT otp FROM users WHERE token = ?");
$stmt->execute([$loggedInUserToken]);
$storedOTP = $stmt->fetchColumn();
if ($enteredOTP == $storedOTP) {
$token = User::getToken();
Db::update("users", array("otp"), array(0), "token = ?", $token);
// OTP verification successful
Messages::success("OTP verification successful. Redirecting to the dashboard...");
Config::redir("index.php");
} else {
// Incorrect OTP
Messages::error("Incorrect OTP. Please try again.");
}
} catch (PDOException $e) {
// Handle database connection error
echo "Connection failed: " . $e->getMessage();
}
}
?>
<html>
<title><?php echo CONFIG::SYSTEM_NAME; ?> : OTP Verification</title>
<?php require_once "inc/head.inc.php"; ?>
<head>
</head>
<body>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-1'></div>
<div class='col-md-4'></div>
<div class='col-md-15'>
<div class='content-area'>
<div class='content-header'></div>
<div class='content-body'>
<center>
<div class='badge-header'>Please Enter the OTP received in your Email Address</div>
</center>
<div class='row'>
<div class='col-md-3'></div>
<div class='container'>
<div class='row'>
<div class='col-md-6 mx-auto'>
<div class='form-holder'>
<?php Db::form(array("Verification code"), 3, array("verification_code"), array("number"), "verify"); ?>
</div>
</div>
</div>
</div>
<div class='col-md-3'></div>
</div><!-- end of the content area -->
</div>
</div>
</div>
</div>
</div>
<?php include 'inc/footer.inc.php'; ?>
</body>
</html>