forked from supagusti/onetimepassword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.php
55 lines (40 loc) · 1.36 KB
/
demo.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
<?php
include 'include/base32.php';
include 'include/phpqrcode.php';
include 'include/oauth_totp.php';
// Initial Settings
$MY_SECRET="ThisIsATestSample";
$MY_SITE_NAME="testapp";
// Determine the time window
$time_window = 30;
// Get the exact time from the server
$exact_time = microtime(true);
// Round the time down to the time window
$rounded_time = floor($exact_time/$time_window);
// Generate TOTP
$totp_generated=oauth_totp($MY_SECRET, $rounded_time, $digits=6, $crypto='sha1');
// BASE32 ENCODING
$base32obj = new Base32();
$base32SECRET = $base32obj->base32_encode($MY_SECRET);
//BASE32 DECODE would be: $string = $a->base32_decode('KRSXG5A='); // Test
// Generate QR Code
// QRcode::png('some othertext 1234'); // creates code image and outputs it directly into browser
$QRTEXT="otpauth://totp/".$MY_SITE_NAME."?secret=".$base32SECRET;
QRcode::png($QRTEXT, 'tmp/qrcode.png');
// Site Output for Demo
echo "<h1>DEMO - RFC 6238 for Time-Based One-Time Passwords </h1>";
echo "exact_time=".date("D M j G:i:s T Y",$exact_time);
echo "</BR>";
echo "TOTP(generated)=".$totp_generated;
echo "</BR></BR>";
echo "MY_SECRET=".$MY_SECRET;
echo "</BR>";
echo "base32(MY_SECRET)=".$base32SECRET;
echo "</BR>";
echo "MY_SITE_NAME=".$MY_SITE_NAME;
echo "</BR>";
echo "QRTEXT=".$QRTEXT;
echo "</BR>";
echo "</BR>";
echo '<img src="tmp/qrcode.png" alt="QR-Code missing :-(">';
?>