Password::rehash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace DrMVC\Password;
4
5
/**
6
 * Class Password
7
 * @package DrMVC\Password
8
 */
9
class Password implements PasswordInterface
10
{
11
12
    /**
13
     * Hash the password using the specified algorithm
14
     *
15
     * @param   string $password The password to hash
16
     * @param   int $algorithm The algorithm to use (Defined by PASSWORD_* constants)
17
     * @param   array $options The options for the algorithm to use
18
     * @return  string|bool
19
     */
20
    public function make(string $password, int $algorithm = PASSWORD_DEFAULT, array $options = [])
21
    {
22
        return password_hash($password, $algorithm, $options);
23
    }
24
25
    /**
26
     * Get information about the password hash. Returns an array of the information
27
     * that was used to generate the password hash.
28
     *
29
     * @param   string $hash
30
     * @return  array
31
     */
32
    public function info(string $hash): array
33
    {
34
        return password_get_info($hash);
35
    }
36
37
    /**
38
     * Determine if the password hash needs to be rehashed according to the options provided.
39
     * If the answer is true, after validating the password using password_verify, rehash it.
40
     *
41
     * @param   string $hash The hash to test
42
     * @param   int $alg The algorithm used for new password hashes
43
     * @param   array $options The options array passed to password_hash
44
     * @return  bool
45
     */
46
    public function rehash($hash, $alg = PASSWORD_DEFAULT, array $options = []): bool
47
    {
48
        return password_needs_rehash($hash, $alg, $options);
49
    }
50
51
    /**
52
     * Verify a password against a hash using a timing attack resistant approach
53
     *
54
     * @param   string $password The password to verify
55
     * @param   string $hash The hash to verify against
56
     * @return  bool
57
     */
58
    public function verify($password, $hash): bool
59
    {
60
        return password_verify($password, $hash);
61
    }
62
63
}
64