1 | <?php |
||
5 | class AuthenticationToken { |
||
6 | /** @var int byte length of the token (non-user part) */ |
||
7 | const TOKENLENGTH = 32; |
||
8 | |||
9 | /** @var string path to the file */ |
||
10 | protected $file; |
||
11 | /** @var string the md5 of the user name */ |
||
12 | protected $md5; |
||
13 | |||
14 | /** @var string|null the user name */ |
||
15 | protected $user; |
||
16 | /** @var string|null the full token */ |
||
17 | protected $token; |
||
18 | |||
19 | /** |
||
20 | * AuthenticationToken constructor. |
||
21 | * |
||
22 | * @param string $md5 |
||
23 | * @param string|null $user |
||
24 | */ |
||
25 | protected function __construct($md5, $user = null) { |
||
31 | |||
32 | /** |
||
33 | * Create an instance from a given token |
||
34 | * |
||
35 | * @param string $token |
||
36 | * @return AuthenticationToken |
||
37 | */ |
||
38 | static public function fromToken($token) { |
||
43 | |||
44 | /** |
||
45 | * Create an instance from a given user name |
||
46 | * |
||
47 | * @param string $user |
||
48 | * @return AuthenticationToken |
||
49 | */ |
||
50 | static public function fromUser($user) { |
||
57 | |||
58 | /** |
||
59 | * Check the user supplied token against the stored one |
||
60 | * |
||
61 | * @param string $token the user supplied token |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function check($token) { |
||
69 | |||
70 | /** |
||
71 | * Reset the user's token |
||
72 | * |
||
73 | * @return string|false the new token if successful |
||
74 | */ |
||
75 | public function reset() { |
||
85 | |||
86 | /** |
||
87 | * Get the user's current token |
||
88 | * |
||
89 | * @return string|false the token, false if none is set |
||
90 | */ |
||
91 | public function getToken() { |
||
95 | |||
96 | /** |
||
97 | * Get the user of this token |
||
98 | * |
||
99 | * @return bool|string |
||
100 | */ |
||
101 | public function getUser() { |
||
105 | |||
106 | /** |
||
107 | * Removes the user's token |
||
108 | */ |
||
109 | public function clear() { |
||
112 | |||
113 | /** |
||
114 | * Load the data |
||
115 | * |
||
116 | * @return bool successfully loaded |
||
117 | */ |
||
118 | protected function load() { |
||
125 | |||
126 | /** |
||
127 | * Adjusted Base64 method |
||
128 | * |
||
129 | * @param string $bytes |
||
130 | * @return string |
||
131 | */ |
||
132 | protected static function tokenchars($bytes) { |
||
137 | |||
138 | /** |
||
139 | * Generate an alphanumeric token of given length |
||
140 | * |
||
141 | * @param int $length |
||
142 | * @return string |
||
143 | */ |
||
144 | protected function createToken($length = 30) { |
||
157 | |||
158 | } |
||
159 |