Completed
Pull Request — 2.x (#82)
by Hari
04:17 queued 02:38
created

PasswordVerifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 45
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A verify() 0 8 2
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Auth\Verifier;
10
11
/**
12
 *
13
 * Htaccess password Verifier
14
 *
15
 * @package Aura.Auth
16
 *
17
 */
18
class PasswordVerifier implements VerifierInterface
19
{
20
    /**
21
     *
22
     * The hashing algorithm to use.
23
     *
24
     * @var string|int
25
     *
26
     */
27
    protected $algo;
28
29
    /**
30
     *
31
     * Constructor.
32
     *
33
     * @param string|int $algo The hashing algorithm to use.
34
     *
35
     */
36 11
    public function __construct($algo)
37
    {
38 11
        $this->algo = $algo;
39 11
    }
40
41
    /**
42
     *
43
     * Verifies a password against a hash.
44
     *
45
     * @param string $plaintext Plaintext password.
46
     *
47
     * @param string $hashvalue The comparison hash.
48
     *
49
     * @param array $extra Optional array if used by verify
50
     *
51
     * @return bool
52
     *
53
     */
54 4
    public function verify($plaintext, $hashvalue, array $extra = array())
55
    {
56 4
        if (is_string($this->algo)) {
57 4
            return hash($this->algo, $plaintext) === $hashvalue;
58
        } else {
59
            return password_verify($plaintext, $hashvalue);
60
        }
61
    }
62
}
63