-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.php
33 lines (21 loc) · 849 Bytes
/
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
<?php
use Kelunik\TwoFactor\Oath;
require __DIR__ . "/../vendor/autoload.php";
$oath = new Oath;
$key = $oath->generateKey();
$uri = $oath->getUri("Example", "[email protected]", $key);
$uri = "https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=" . \urlencode($uri);
print <<<HELP
Just a few steps before you can see it working:
- Copy the following URI to your browser.
- Scan the QR code with your Authenticator (or any other) app.
- Compare the codes generated here and on your phone.
{$uri}
Your mobile and desktop / server clock may be not totally in sync,
so one or the other might be a bit faster showing new codes.
You can stop this script by pressing Ctrl+C.
HELP;
while (true) {
\sleep(30 - \time() % 30);
print " [ " . \date("H:i:s") . " ] " . $oath->generateTotp($key) . PHP_EOL;
}