Conditions | 6 |
Paths | 9 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
27 | protected function isDeviceTrusted(): bool |
||
28 | { |
||
29 | $cookie = request()->cookie('2fa_trusted_device'); |
||
30 | |||
31 | if (! $cookie) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | try { |
||
36 | $data = json_decode($cookie, true); |
||
|
|||
37 | |||
38 | // Check if cookie contains the required data |
||
39 | if (! isset($data['user_id'], $data['token'], $data['expires_at'])) { |
||
40 | return false; |
||
41 | } |
||
42 | |||
43 | // Check if the token belongs to the current user |
||
44 | if ((int) $data['user_id'] !== (int) $this->getUser()->id) { |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | // Check if the token is expired |
||
49 | if (time() > $data['expires_at']) { |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | // Device is trusted and token is valid |
||
54 | return true; |
||
55 | } catch (\Exception $e) { |
||
56 | return false; |
||
57 | } |
||
76 |