-
Notifications
You must be signed in to change notification settings - Fork 6
/
totp-xmlhttp.php
47 lines (34 loc) · 1.18 KB
/
totp-xmlhttp.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
<?php
include 'include/oauth_totp.php';
session_start();
if( !$_SESSION['loggedIn'] )
{
echo 'error';
exit();
}
$digits=$_SESSION['digits'];
$algorithm=$_SESSION['algorithm'];
$period= $_SESSION['period'];
// Initial Settings - Seed
$MY_SECRET=$_SESSION['seed'];
// Initial Settings - Trim Time
$trim=$_SESSION['trim'];
// Determine the time window
$time_window = $period;
//echo "TimeWindow:".$time_window."<br>";
// Get the exact time from the server
$exact_time = microtime(true)+$trim;
//echo "exact_time:".$exact_time".<br>";
// Round the time down to the time window
$rounded_time = floor($exact_time/$time_window);
//echo "rounded time:".$rounded_time."<br>";
// Seconds until key expires
$str_time_to_expire = $exact_time/$time_window;
$array_time_to_expire= explode(".", $str_time_to_expire);
$erg_time_to_expire="0.".$array_time_to_expire[1];
$time_to_expire=$time_window-floor($erg_time_to_expire*$time_window);
// Generate TOTP
$totp_generated=oauth_totp($MY_SECRET, $rounded_time, $digits, $algorithm);
echo '<h1>'.$totp_generated."</h1>";
echo "time to expire: ".$time_to_expire."s";
?>