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

PasswordManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A verify() 0 4 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