3 require_once("../lib/lib.php");
4 if(isset($_REQUEST["action"])) {
5 switch($_REQUEST["action"]) {
7 unlink("/tmp/gaexpage.db");
13 $ga = new GoogleAuthenticator("/tmp/gaexpage.db");
16 <h1>Example Page for GA4PHP</h1>
19 if(isset($_REQUEST["action"])) {
20 switch($_REQUEST["action"]) {
22 $username = $_REQUEST["username"];
23 $pr = preg_match('/^[a-zA-Z0-9@\.]+$/',"$username");
24 $ttype = $_REQUEST["ttype"];
26 if(strlen($username)<3) {
27 echo "<font color=\"red\">Sorry, username must be at least 3 chars</font>";
29 echo "<font color=\"red\">Sorry, username can only contain a-z, A-Z, 0-9 @ and .</font>";
31 $key = $ga->setupUser($username, $ttype);
32 $keyinhex = $ga->helperb322hex($key);
33 $url = urlencode($ga->createURL($username, $key, $ttype));
34 echo "QRCode for user \"$username\" is <img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=120x120\"> or type in $key (google authenticator) or $keyinhex (for most other otp's)";
39 $username = $_REQUEST["username"];
40 $code = $_REQUEST["code"];
41 if($ga->authenticateUser($username, $code)) {
42 echo "<font color=\"green\">Passed!</font>";
44 echo "<font color=\"red\">Failed!</font>";
48 $username = $_REQUEST["username"];
49 $code1 = $_REQUEST["code1"];
50 $code2 = $_REQUEST["code2"];
51 if($ga->resyncCode($username, $code1, $code2)) {
52 echo "<font color=\"green\">Passed!</font>";
54 echo "<font color=\"red\">Failed!</font>";
63 <h2>Destroy the DB</h2>
64 <a href="index.php?action=destroy">This is UNDOABLE - but this is a test system, so you dont care</a>
65 <h2>Create a User:</h2>
66 <form method="post" action="index.php?action=createuser">
67 Username: <input type="text" name="username"><br>
68 Type: <select name="ttype"><option value="HOTP">HOTP</option><option value="TOTP">TOTP</option></select><br>
69 <input type="submit" name="go" value="go"><br>
73 <form method="post" action="index.php?action=authuser">
74 Username: <select name="username">
76 $res = $ga->getUserList();
77 foreach($res as $row) {
78 echo "<option value=\"".$row."\">".$row."</option>";
82 Code: <input type="text" name="code"><br>
83 <input type="submit" name="go" value="go"><br>
86 <h2>Resync Code (only valid for HOTP codes)</h2>
87 <form method="post" action="index.php?action=resync">
88 Username: <select name="username">
90 $res = $ga->getUserList();
91 foreach($res as $row) {
92 echo "<option value=\"".$row."\">".$row."</option>";
96 Code one: <input type="text" name="code1"><br>
97 Code two: <input type="text" name="code2"><br>
98 <input type="submit" name="go" value="go"><br>