3 require_once("../lib/lib.php");
5 $ga = new GoogleAuthenticator("/tmp/gaexpage.db");
8 <h1>Example Page for GA4PHP</h1>
11 if(isset($_REQUEST["action"])) {
12 switch($_REQUEST["action"]) {
14 $username = $_REQUEST["username"];
15 $pr = preg_match('/^[a-zA-Z0-9@\.]+$/',"$username");
17 if(strlen($username)<3) {
18 echo "<font color=\"red\">Sorry, username must be at least 3 chars</font>";
20 echo "<font color=\"red\">Sorry, username can only contain a-z, A-Z, 0-9 @ and .</font>";
22 $url = $ga->setupUser($username);
23 echo "QRCode for user \"$username\" is <img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=120x120\"> or type in $url (actually its just the code on the end of the url)";
28 $username = $_REQUEST["username"];
29 $code = $_REQUEST["code"];
30 if($ga->authenticateUser($username, $code)) {
31 echo "<font color=\"green\">Passed!</font>";
33 echo "<font color=\"red\">Failed!</font>";
37 $username = $_REQUEST["username"];
38 $code1 = $_REQUEST["code1"];
39 $code2 = $_REQUEST["code2"];
40 if($ga->resyncCode($username, $code1, $code2)) {
41 echo "<font color=\"green\">Passed!</font>";
43 echo "<font color=\"red\">Failed!</font>";
47 unlink("/tmp/gaexpage.db");
55 <h2>Destroy the DB</h2>
56 <a href="index.php?action=destroy">This is UNDOABLE - but this is a test system, so you dont care</a>
57 <h2>Create a User:</h2>
58 <form method="post" action="index.php?action=createuser">
59 Username: <input type="text" name="username"><br>
60 Type (ignored for now): <select name="ttype"><option value="HOTP">HOTP</option><option value="TOTP">TOTP</option></select><br>
61 <input type="submit" name="go" value="go"><br>
65 <form method="post" action="index.php?action=authuser">
66 Username: <select name="username">
68 $res = $ga->getUserList();
69 foreach($res as $row) {
70 echo "<option value=\"".$row."\">".$row."</option>";
74 Code: <input type="text" name="code"><br>
75 <input type="submit" name="go" value="go"><br>
78 <h2>Resync Code (only valid for HOTP codes)</h2>
79 <form method="post" action="index.php?action=resync">
80 Username: <select name="username">
82 $res = $ga->getUserList();
83 foreach($res as $row) {
84 echo "<option value=\"".$row."\">".$row."</option>";
88 Code one: <input type="text" name="code1"><br>
89 Code two: <input type="text" name="code2"><br>
90 <input type="submit" name="go" value="go"><br>