3 * This example is simply an example of how a provisioning page may look
4 * which includes such funcationality as createing users, initialising their
5 * data, create a token for them, testing the token and resyncing it as needed
9 // Require our php libraries
10 require_once("token.php");
11 require_once("dbfunctions.php");
12 require_once("input.php");
14 // now lets get an instance of our class
18 // this part of the page resonds to user input
23 <h1>Welcome to GA Provisioning!</h1>
26 // in this part of the code we look for "success" or "fail" things
27 if(isset($_REQUEST["success"])) {
28 echo "<br><font color=\"green\">".$_REQUEST["success"]."</font><br>";
30 if(isset($_REQUEST["failure"])) {
31 echo "<br><font color=\"red\">".$_REQUEST["failure"]."</font><br>";
36 <b>How to user this page</b> - Create a user with the "Users" form. Once a user is created, then in the "Create Token" form,
37 select the user from the drop down box and then select a token type, then click "provision". In the main user list section
38 your user should now have a qrcode representing the key for that user. Pull our your mobile phone (with the google
39 authenticator app from the market) and scan in the code. Next, select the user who's authentication you wish to test from
40 the drop down list under "test authentication" section, generate a code for that user on your phone and click "Auth".
41 this should fail/succeed depending on whether you have typed in the right code.
48 <tr><th>Username/Login</th><th>Fullname</th><th>Has Token?</th><th>Key</th><th>Base 32 Key</th><th>Hex Key</th></tr>
50 // now we get our list of users - this part of the page just has a list of users
51 // and the ability to create new ones. This isnt really in the scope of the
52 // GA4PHP, but for this example, we need to be able to create users, so heres where
55 $result = $db->query("select * from users");
56 foreach($result as $row) {
57 if($myga->hasToken($row["users_username"])) {
59 $type = $myga->getTokenType($row["users_username"]);
61 $type = "- Counter Based";
63 $type = "- Time Based";
65 $hexkey = $myga->getKey($row["users_username"]);
66 $b32key = $myga->helperhex2b32($hexkey);
68 $url = urlencode($myga->createURL($row["users_username"]));
69 $keyurl = "<img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=100x100\">";
81 // now we generate the qrcode for the user
83 echo "<tr><td>".$row["users_username"]."</td><td>".$row["users_fullname"]."</td><td>$hastoken $type</td><td>$keyurl</td><td>$b32key</td><td>$hexkey</td></tr>";
89 <form method="post" action="?action=createuser">
90 Username/login: <input type="text" name="username">
91 Full Name: <input type="text" name="fullname">
92 <input type="submit" name="Add" value="Add">
100 <h2>Create Token</h2>
101 This form allows you to provision a token for the user<br>
102 <form method="post" action="?action=provision">
103 User:<select name="user">
105 // here we list the users again for a select clause
107 $result = $db->query("select * from users");
108 foreach($result as $row) {
109 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
110 else $hastoken = "- No token";
112 $username = $row["users_username"];
114 echo "<option value=\"$username\">$username $hastoken</option>";
121 <select name="tokentype">
122 <option value="HOTP">Counter Based</option>
123 <option value="TOTP">Time Based</option>
125 <input type="submit" name="Provision" value="Provision">
129 <h2>Test Authentication</h2>
130 <form method="post" action="?action=auth">
131 User:<select name="user">
133 // here we list the users again for a select clause
135 $result = $db->query("select * from users");
136 foreach($result as $row) {
137 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
138 else $hastoken = "- No token";
140 $username = $row["users_username"];
142 echo "<option value=\"$username\">$username $hastoken</option>";
146 <input type="text" name="tokencode">
147 <input type="submit" name="Auth" value="Auth">
154 print_r($myga->internalGetData("asdf"));