Completed
Push — master ( 5139b6...b16139 )
by Sebastian
02:13
created

EnhancedAuthenticate   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 126
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A login() 0 6 2
A IsAccountLocked() 0 4 1
A getAttemptsLeftWithSameUser() 0 4 1
A getAttemptsLeftWithSameIp() 0 4 1
A getAttemptsLeftWithSameSession() 0 4 1
A isUserBanned() 0 4 1
A isIpBanned() 0 4 1
A isSessionBanned() 0 4 1
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
0 ignored issues
show
Unused Code introduced by
The parameter $userName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $userName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $ip is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $sessionId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $userName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $ip is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The parameter $sessionId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
    {
143
        return true;
144
    }
145
}
146