Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BcryptPasswordHasher | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hash | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| verify | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Plugin\PasswordHasher\Adapter; |
| 11 | |
| 12 | use Override; |
| 13 | use Phexium\Plugin\PasswordHasher\Port\PasswordHasherInterface; |
| 14 | |
| 15 | final readonly class BcryptPasswordHasher implements PasswordHasherInterface |
| 16 | { |
| 17 | public function __construct(private ?int $cost = null) {} |
| 18 | |
| 19 | #[Override] |
| 20 | public function hash(string $plainPassword): string |
| 21 | { |
| 22 | $options = []; |
| 23 | |
| 24 | if ($this->cost !== null) { |
| 25 | $options['cost'] = $this->cost; |
| 26 | } |
| 27 | |
| 28 | return password_hash($plainPassword, PASSWORD_BCRYPT, $options); |
| 29 | } |
| 30 | |
| 31 | #[Override] |
| 32 | public function verify(string $plainPassword, string $hash): bool |
| 33 | { |
| 34 | return password_verify($plainPassword, $hash); |
| 35 | } |
| 36 | } |