Completed
Push — master ( 5a5b2e...66ec7e )
by Matze
04:12
created

PasswordHasher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 3
c 4
b 0
f 3
lcom 1
cbo 0
dl 0
loc 37
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateHash() 0 6 1
A verifyHash() 0 4 1
1
<?php
2
3
namespace BrainExe\Core\Authentication;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Annotations\Annotations\Service;
7
8
/**
9
 * @Service("Core.Authentication.PasswordHasher", public=false)
10
 */
11
class PasswordHasher
12
{
13
    /**
14
     * @var int
15
     */
16
    private $cost;
17
18 1
    /**
19
     * @Inject("%application.passwordHasher.cost%")
20 1
     * @param int $cost
21 1
     */
22
    public function __construct(int $cost)
23
    {
24
        $this->cost = $cost;
25
    }
26
27
    /**
28
     * @param string $password
29
     * @return string $hash
30 1
     */
31
    public function generateHash(string $password) : string
32 1
    {
33
        return password_hash($password, PASSWORD_BCRYPT, [
34
            'cost' => $this->cost
35
        ]);
36
    }
37
38
    /**
39
     * @param string $password
40
     * @param string $hash
41
     * @return bool
42
     */
43
    public function verifyHash(string $password, string $hash) : bool
44
    {
45
        return password_verify($password, $hash);
46
    }
47
}
48