-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_code.php
48 lines (34 loc) · 989 Bytes
/
check_code.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
<?php
require __DIR__ . '/vendor/autoload.php';
use OTPHP\TOTP;
$secret = 'OFRGWZDDNRWTI4DOGQ4XIOLWMZSGU3I='; // it must be a Base32 encoded string
$otp = TOTP::create($secret);
$success = false;
$inCorrectAnswer = false;
if (!empty($_POST['answer'])) {
$answer = $_POST['answer'];
if ($otp->verify($answer)) {
$success = true;
} else {
$inCorrectAnswer = true;
}
}
?>
<h4>Check code via the app</h4>
<?php if ($inCorrectAnswer) { ?>
<h5 style="color: red">Your answer is incorrect</h5>
<?php } else { ?>
<?php if ($success) { ?>
<h5 style="color: green">All is Okay</h5>
<?php } else { ?>
<h5 style="color: gray">You didn't check it yet</h5>
<?php } ?>
<?php } ?>
<form action="./check_code.php" method="post">
<label for="answer">Your answer</label>
<br>
<input id="answer" type="text" name="answer">
<input type="submit" value="Send">
</form>
<hr>
<a href="./new_code.php">Scan a QR code</a>