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

PasswordHasher::__construct()   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
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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