1 | <?php |
||
13 | class TOTP |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $label; |
||
20 | |||
21 | /** |
||
22 | * @var integer |
||
23 | */ |
||
24 | private $digits; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $digest; |
||
30 | |||
31 | /** |
||
32 | * @var integer |
||
33 | */ |
||
34 | private $interval; |
||
35 | |||
36 | /** |
||
37 | * @Inject({ |
||
38 | * "%totp.label%", |
||
39 | * "%totp.digits%", |
||
40 | * "%totp.digest%", |
||
41 | * "%totp.interval%" |
||
42 | * }) |
||
43 | * @param string $label |
||
44 | * @param integer $digits |
||
45 | * @param string $digest |
||
46 | * @param integer $interval |
||
47 | * @param Time $time |
||
48 | */ |
||
49 | 3 | public function __construct( |
|
62 | |||
63 | /** |
||
64 | * @param string $secret |
||
65 | * @param int $otp |
||
66 | * @param int|null $timestamp |
||
67 | * @return bool |
||
68 | */ |
||
69 | 2 | public function verify(string $secret, $otp, int $timestamp = null) : bool |
|
86 | |||
87 | /** |
||
88 | * @param string $secret |
||
89 | * @return int |
||
90 | */ |
||
91 | public function current(string $secret) |
||
95 | |||
96 | /** |
||
97 | * @param string $secret |
||
98 | * @return string |
||
99 | */ |
||
100 | 1 | public function getUri(string $secret) : string |
|
114 | |||
115 | /** |
||
116 | * @param int $timestamp |
||
117 | * @param string $secret |
||
118 | * @return int |
||
119 | */ |
||
120 | 2 | private function at($timestamp, $secret) |
|
124 | |||
125 | /** |
||
126 | * @param integer $input |
||
127 | * @param string $secret |
||
128 | * @return int |
||
129 | */ |
||
130 | 2 | private function generateOTP($input, $secret) |
|
147 | |||
148 | /** |
||
149 | * @param int $timestamp |
||
150 | * @return int |
||
151 | */ |
||
152 | 2 | private function timecode($timestamp) |
|
156 | |||
157 | /** |
||
158 | * @param int $int |
||
159 | * @return string |
||
160 | */ |
||
161 | 2 | private function intToBytestring($int) |
|
171 | } |
||
172 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: