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

PasswordHasher::confirmPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
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