1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Linna Framework. |
5
|
|
|
* |
6
|
|
|
* @author Sebastian Rapetti <[email protected]> |
7
|
|
|
* @copyright (c) 2017, Sebastian Rapetti |
8
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
9
|
|
|
*/ |
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Linna\Authentication; |
13
|
|
|
|
14
|
|
|
use Linna\Session\Session; |
15
|
|
|
use Linna\Shared\ClassOptionsTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Extend basic user authentication system with more security checks. |
19
|
|
|
*/ |
20
|
|
|
class EnhancedAuthenticate extends Authenticate |
21
|
|
|
{ |
22
|
|
|
use ClassOptionsTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array An associative array containing options |
26
|
|
|
*/ |
27
|
|
|
protected $options = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class Constructor |
31
|
|
|
* |
32
|
|
|
* @param Session $session |
33
|
|
|
* @param Password $password |
34
|
|
|
* @param array $options |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Session $session, Password $password, array $options = []) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($session, $password); |
39
|
|
|
|
40
|
|
|
//set options |
41
|
|
|
$this->setOptions($options); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Try to attempt login with the informations passed by param. |
46
|
|
|
* |
47
|
|
|
* @param string $userName |
48
|
|
|
* @param string $password |
49
|
|
|
* @param string $storedUserName |
50
|
|
|
* @param string $storedPassword |
51
|
|
|
* @param int $storedId |
52
|
|
|
* |
53
|
|
|
* @return boolean |
54
|
|
|
*/ |
55
|
|
|
public function login(string $userName, string $password, string $storedUserName = '', string $storedPassword = '', int $storedId = 0) |
56
|
|
|
{ |
57
|
|
|
if (parent::login($userName, $password, $storedUserName, $storedPassword, $storedId)) { |
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Check if an account is locked after too much failed. |
64
|
|
|
* |
65
|
|
|
* @param string $userName |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function IsAccountLocked(string $userName) : bool |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Return how many attemps are left for incorrect password. |
76
|
|
|
* |
77
|
|
|
* @param string $userName |
78
|
|
|
* |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
|
|
public function getAttemptsLeftWithSameUser(string $userName) : int |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
return 0; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Return how many attemps are left for same ip. |
88
|
|
|
* |
89
|
|
|
* @param string $ip |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
|
|
public function getAttemptsLeftWithSameIp(string $ip) : int |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
return 0; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return how many attemps are left for same session id. |
100
|
|
|
* |
101
|
|
|
* @param string $sessionId |
102
|
|
|
* |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
|
|
public function getAttemptsLeftWithSameSession(string $sessionId) : int |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
return 0; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Check if an user is banned from do login. |
112
|
|
|
* |
113
|
|
|
* @param string $userName |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function isUserBanned(string $userName) : bool |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
return true; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Check if an ip address is banned from do login. |
124
|
|
|
* |
125
|
|
|
* @param string $ip |
126
|
|
|
* |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
public function isIpBanned(string $ip) : bool |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Check if a session id is banned from do login. |
136
|
|
|
* |
137
|
|
|
* @param string $sessionId |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function isSessionBanned(string $sessionId) : bool |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
return true; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.