Password   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 5 2
A __construct() 0 4 1
1
<?php
2
namespace LibSSH2\Authentication;
3
4
use LibSSH2\Configuration;
5
6
/**
7
 * Password class.
8
 *
9
 * Username and password based authentication.
10
 *
11
 * @package LibSSH2\Authentication
12
 */
13
class Password extends Configuration implements Authentication
14
{
15
    /**
16
     * Username.
17
     *
18
     * @var string
19
     */
20
    protected $username;
21
22
    /**
23
     * Password.
24
     *
25
     * @var string
26
     */
27
    protected $password;
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param  object $configuration Configuration object
33
     * @return void
34
     */
35
    public function __construct(Configuration $configuration)
36
    {
37
        $this->username = $configuration->get_username();
38
        $this->password = $configuration->get_password();
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    final public function authenticate($resource)
45
    {
46
        if (@ssh2_auth_password($resource, $this->username, $this->password) === FALSE)
47
        {
48
            throw new \RuntimeException('Password based authentication failed.');
49
        }
50
    }
51
}
52