Passed
Push — master ( d3cc39...f2a84f )
by Melech
03:59
created

PasswordHasher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
dl 0
loc 28
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hashPassword() 0 6 1
A confirmPassword() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Auth\Hasher;
15
16
use Valkyrja\Auth\Hasher\Contract\PasswordHasher as Contract;
17
18
use const PASSWORD_DEFAULT;
19
20
/**
21
 * Class PasswordHasher.
22
 *
23
 * @author Melech Mizrachi
24
 */
25
class PasswordHasher implements Contract
26
{
27
    /**
28
     * Hash a given password.
29
     *
30
     * @param non-empty-string $password The password to hash
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
31
     *
32
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
33
     */
34
    public function hashPassword(string $password): string
35
    {
36
        /** @var non-empty-string $hashedPassword */
37
        $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
38
39
        return $hashedPassword;
40
    }
41
42
    /**
43
     * Compare an plain text password with a given hashed password.
44
     *
45
     * @param string $password       The plain text password
46
     * @param string $hashedPassword The hashed password
47
     *
48
     * @return bool
49
     */
50
    public function confirmPassword(string $password, string $hashedPassword): bool
51
    {
52
        return password_verify($password, $hashedPassword);
53
    }
54
}
55