Completed
Push — master ( 67ec2b...d15b3f )
by Dominik
02:51
created

PasswordManager::hash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Chubbyphp\Security\Authentication;
4
5
use Chubbyphp\Security\Authentication\Exception\EmptyPasswordException;
6
7
final class PasswordManager implements PasswordManagerInterface
8
{
9
    /**
10
     * @param string $password
11
     *
12
     * @return string
13
     *
14
     * @throws EmptyPasswordException
15
     */
16
    public function hash(string $password): string
17
    {
18
        if ('' === $password) {
19
            throw EmptyPasswordException::create();
20
        }
21
22
        return password_hash($password, PASSWORD_DEFAULT);
23
    }
24
25
    /**
26
     * @param string $password
27
     * @param string $hash
28
     *
29
     * @return bool
30
     */
31
    public function verify(string $password, string $hash): bool
32
    {
33
        return password_verify($password, $hash);
34
    }
35
}
36