PluginProbe
Two Factor Authentication / 1.2.6
Two Factor Authentication v1.2.6
1.12.2 1.13.0 1.14.10 1.14.11 1.14.14 1.14.15 1.14.16 1.14.17 1.14.23 1.14.24 1.14.26 1.14.27 1.14.3 1.14.4 1.14.5 1.14.7 1.14.8 1.15.5 1.16.0 1.2.10 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 All 98 releases
two-factor-authentication / hotp-php-master / example.php

example.php in Two Factor Authentication 1.2.6, at hotp-php-master/example.php

161 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 HOTP Example File
5 */
6 require_once 'hotp.php';
7
8 $key = '12345678901234567890';
9
10 $table = array(
11 'HOTP' => array(
12 0 => array(
13 'HMAC' => 'cc93cf18508d94934c64b65d8ba7667fb7cde4b0',
14 'hex' => '4c93cf18',
15 'dec' => '1284755224',
16 'hotp' => '755224',
17 ),
18 1 => array(
19 'HMAC' => '75a48a19d4cbe100644e8ac1397eea747a2d33ab',
20 'hex' => '41397eea',
21 'dec' => '1094287082',
22 'hotp' => '287082',
23 ),
24 2 => array(
25 'HMAC' => '0bacb7fa082fef30782211938bc1c5e70416ff44',
26 'hex' => '82fef30',
27 'dec' => '137359152',
28 'hotp' => '359152',
29 ),
30 3 => array(
31 'HMAC' => '66c28227d03a2d5529262ff016a1e6ef76557ece',
32 'hex' => '66ef7655',
33 'dec' => '1726969429',
34 'hotp' => '969429',
35 ),
36 4 => array(
37 'HMAC' => 'a904c900a64b35909874b33e61c5938a8e15ed1c',
38 'hex' => '61c5938a',
39 'dec' => '1640338314',
40 'hotp' => '338314',
41 ),
42 5 => array(
43 'HMAC' => 'a37e783d7b7233c083d4f62926c7a25f238d0316',
44 'hex' => '33c083d4',
45 'dec' => '868254676',
46 'hotp' => '254676',
47 ),
48 6 => array(
49 'HMAC' => 'bc9cd28561042c83f219324d3c607256c03272ae',
50 'hex' => '7256c032',
51 'dec' => '1918287922',
52 'hotp' => '287922',
53 ),
54 7 => array(
55 'HMAC' => 'a4fb960c0bc06e1eabb804e5b397cdc4b45596fa',
56 'hex' => '4e5b397',
57 'dec' => '82162583',
58 'hotp' => '162583',
59 ),
60 8 => array(
61 'HMAC' => '1b3c89f65e6c9e883012052823443f048b4332db',
62 'hex' => '2823443f',
63 'dec' => '673399871',
64 'hotp' => '399871',
65 ),
66 9 => array(
67 'HMAC' => '1637409809a679dc698207310c8c7fc07290d9e5',
68 'hex' => '2679dc69',
69 'dec' => '645520489',
70 'hotp' => '520489',
71 ),
72 ),
73 'TOTP' => array(
74 '59' => array(
75 'totp' => '94287082',
76 ),
77 '1111111109' => array(
78 'totp' => '07081804',
79 ),
80 '1111111111' => array(
81 'totp' => '14050471',
82 ),
83 '1234567890' => array(
84 'totp' => '89005924',
85 ),
86 '2000000000' => array(
87 'totp' => '69279037',
88 ),
89 ),
90 );
91
92 echo <<<DOCBLOCK
93 <!DOCTYPE><html><head></head><body><pre>
94 http://www.ietf.org/rfc/rfc4226.txt
95 http://tools.ietf.org/html/draft-mraihi-totp-timebased-06
96
97 TEST VECTOR VERIFICATION
98
99 HOTP Tests:
100
101 DOCBLOCK;
102
103 echo "Count Method Value Pass/Fail\n";
104 echo "----------------------------------------------------------------------\n";
105
106 // loop over all HOTP table results, and calculate the matching value
107 foreach ($table['HOTP'] as $seed => $results) {
108 $hotp = HOTP::generateByCounter($key, $seed);
109 $first = true;
110 foreach ($results as $type => $calc) {
111 if ($first) {
112 echo str_pad($seed, 4, ' ', STR_PAD_LEFT);
113 $first = false;
114 }
115 else {
116 echo ' ';
117 }
118 echo ' ';
119 echo str_pad($type, 5, ' ', STR_PAD_RIGHT);
120 echo ' ';
121 echo str_pad($calc, 47, ' ', STR_PAD_RIGHT);
122 echo ' ';
123 $method = 'to'.(ucfirst(str_replace('HMAC', 'string', $type)));
124 echo str_pad(($calc == $hotp->$method(6)) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT);
125 echo "\n";
126 }
127 }
128
129 echo <<<DOCBLOCK
130
131 TOTP Tests:
132
133 DOCBLOCK;
134
135 echo "Time (sec) Value Pass/Fail\n";
136 echo "----------------------------------------------------------------------\n";
137
138 // now echo over the TOTP table
139 foreach ($table['TOTP'] as $seed => $results) {
140 $totp = HOTP::generateByTime($key, 30, $seed);
141 $first = true;
142 foreach ($results as $type => $calc) {
143 if ($first) {
144 echo str_pad($seed, 10, ' ', STR_PAD_LEFT);
145 $first = false;
146 }
147 else {
148 echo ' ';
149 }
150 echo ' ';
151 echo str_pad($calc, 47, ' ', STR_PAD_RIGHT);
152 echo ' ';
153 $method = 'to'.(ucfirst(str_replace('totp', 'hotp', $type)));
154 echo str_pad(($calc == $totp->$method(8)) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT);
155 echo "\n";
156 }
157 }
158
159 echo '</pre></body></html>';
160
161