Completed
Push — master ( a07505...59e140 )
by Sebastian
02:27
created

getAttemptsLeftWithSameSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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\Authentication\EnhancedAuthenticateMapperInterface;
15
use Linna\Session\Session;
16
use Linna\Shared\ClassOptionsTrait;
17
18
/**
19
 * Extend basic user authentication system with more security checks.
20
 */
21
class EnhancedAuthenticate extends Authenticate
22
{
23
    use ClassOptionsTrait;
24
    
25
    /**
26
     * @var array An associative array containing options
27
     */
28
    protected $options = [
29
        'maxAttemptsForUserName' => 5,
30
        'maxAttemptsForSessionId' => 10,
31
        'maxAttemptsForIpAddress' => 20,
32
        'maxAttemptsForSecond' => 40,
33
        'banTimeInSeconds' => 900 //15 minutes
34
    ];
35
    
36
    /**
37
     * @var EnhancedAuthenticateMapperInterface Enhanced Authenticate Mapper
38
     */
39
    private $enhancedAuthenticateMapper;
40
    
41
    /**
42
     * Class Constructor
43
     *
44
     * @param Session  $session
45
     * @param Password $password
46
     * @param array    $options
47
     */
48
    public function __construct(
49
            Session $session,
50
            Password $password,
51
            EnhancedAuthenticateMapperInterface $enhancedAuthenticateMapper,
52
            array $options = []
53
        ) {
54
        parent::__construct($session, $password);
55
        
56
        $this->enhancedAuthenticateMapper = $enhancedAuthenticateMapper;
57
        //set options
58
        $this->setOptions($options);
59
    }
60
    
61
    /**
62
     * Return how many attemps are left for incorrect password.
63
     *
64
     * @param string $userName
65
     *
66
     * @return int
67
     */
68
    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...
69
    {
70
        return 0;
71
    }
72
    
73
    /**
74
     * Return how many attemps are left for same session id.
75
     *
76
     * @param string $sessionId
77
     *
78
     * @return int
79
     */
80
    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...
81
    {
82
        return 0;
83
    }
84
    
85
    /**
86
     * Return how many attemps are left for same ip.
87
     *
88
     * @param string $ipAddress
89
     *
90
     * @return int
91
     */
92
    public function getAttemptsLeftWithSameIp(string $ipAddress) : int
0 ignored issues
show
Unused Code introduced by
The parameter $ipAddress 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...
93
    {
94
        return 0;
95
    }
96
    
97
    /**
98
     * Check if an user is banned from do login.
99
     *
100
     * @param string $userName
101
     *
102
     * @return bool
103
     */
104
    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...
105
    {
106
        return true;
107
    }
108
    
109
    /**
110
     * Check if an ip address is banned from do login.
111
     *
112
     * @param string $ipAddress
113
     *
114
     * @return bool
115
     */
116
    public function isIpBanned(string $ipAddress) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $ipAddress 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...
117
    {
118
        return true;
119
    }
120
    
121
    /**
122
     * Check if a session id is banned from do login.
123
     *
124
     * @param string $sessionId
125
     *
126
     * @return bool
127
     */
128
    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...
129
    {
130
        return true;
131
    }
132
}
133