Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PasswordService
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 hashPassword
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 verifyPassword
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 needsRehash
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Auth\Service;
6
7final class PasswordService
8{
9    /**
10     * Hash a password using bcrypt.
11     *
12     * @param string $password
13     */
14    public function hashPassword(string $password): string
15    {
16        return password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
17    }
18
19    /**
20     * Verify a password against a hash.
21     *
22     * @param string $password
23     * @param string $hash
24     */
25    public function verifyPassword(string $password, string $hash): bool
26    {
27        return password_verify($password, $hash);
28    }
29
30    /**
31     * Check if password needs rehashing.
32     *
33     * @param string $hash
34     */
35    public function needsRehash(string $hash): bool
36    {
37        return password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 12]);
38    }
39}