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 use 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 Password: <input type="password" name="password">
93 <input type="submit" name="Add" value="Add">
101 <h2>Create Token</h2>
102 This form allows you to provision a token for the user<br>
103 <form method="post" action="?action=provision">
104 User:<select name="user">
106 // here we list the users again for a select clause
108 $result = $db->query("select * from users");
109 foreach($result as $row) {
110 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
111 else $hastoken = "- No token";
113 $username = $row["users_username"];
115 echo "<option value=\"$username\">$username $hastoken</option>";
122 <select name="tokentype">
123 <option value="HOTP">Counter Based</option>
124 <option value="TOTP">Time Based</option>
126 <input type="submit" name="Provision" value="Provision">
130 <h2>Test Authentication</h2>
131 <form method="post" action="?action=auth">
132 User:<select name="user">
134 // here we list the users again for a select clause
136 $result = $db->query("select * from users");
137 foreach($result as $row) {
138 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
139 else $hastoken = "- No token";
141 $username = $row["users_username"];
143 echo "<option value=\"$username\">$username $hastoken</option>";
147 <input type="text" name="tokencode">
148 <input type="submit" name="Auth" value="Auth">
155 print_r($myga->internalGetData("asdf"));