1 | <?php |
||
8 | class TokenService implements TokenServiceInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var string hash algorithm |
||
12 | */ |
||
13 | const HASH_ALGO = 'sha512'; |
||
14 | |||
15 | /** |
||
16 | * @var string timestamp key |
||
17 | */ |
||
18 | const KEY_TIMESTAMP = 'T'; |
||
19 | |||
20 | /** |
||
21 | * @var string salt key |
||
22 | */ |
||
23 | const KEY_SALT = 'S'; |
||
24 | |||
25 | /** |
||
26 | * @var string hash key |
||
27 | */ |
||
28 | const KEY_HASH = 'H'; |
||
29 | |||
30 | /** |
||
31 | * @var int token is valid n seconds from now (prevents submission quicker than a human) |
||
32 | */ |
||
33 | public $valid_from = 5; |
||
34 | |||
35 | /** |
||
36 | * @var int token is valid until n seconds from now (token expires after this time) |
||
37 | */ |
||
38 | public $valid_to = 1200; |
||
39 | |||
40 | /** |
||
41 | * @var string secret salt |
||
42 | */ |
||
43 | private $secret; |
||
44 | |||
45 | /** |
||
46 | * @var TokenStoreInterface |
||
47 | */ |
||
48 | private $store; |
||
49 | |||
50 | /** |
||
51 | * @var int timestamp |
||
52 | */ |
||
53 | public $timestamp; |
||
54 | |||
55 | /** |
||
56 | * @param TokenStoreInterface $store |
||
57 | * @param string $secret secret salt (unique to your form or controller) |
||
58 | */ |
||
59 | 3 | public function __construct(TokenStoreInterface $store, $secret) |
|
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | 3 | public function createToken($name) |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 3 | public function checkToken($name, $token) |
|
114 | |||
115 | /** |
||
116 | * @param string $name |
||
117 | * @param string $salt |
||
118 | * @param int $timestamp |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 3 | private function hash($name, $salt, $timestamp) |
|
128 | } |
||
129 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.