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

PasswordVerifier::verify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 2.0625
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