Test Failed
Pull Request — main (#59)
by Dimitri
06:14
created

Argon2IdHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 34
ccs 0
cts 5
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isUsingCorrectAlgorithm() 0 3 1
A check() 0 11 4
A algorithm() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Security\Hashing\Handlers;
13
14
use RuntimeException;
15
16
/**
17
 * Gestionnaire de hashage basé sur Argon2Id
18
 *
19
 * @credit <a href="http://www.laravel.com">Laravel 11 - \Illuminate\Hashing\Argon2IdHasher</a>
20
 */
21
class Argon2IdHandler extends ArgonHandler
22
{
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @throws RuntimeException
27
     */
28
    public function check(string $value, string $hashedValue, array $options = []): bool
29
    {
30
        if ($hashedValue === '') {
31
            return false;
32
        }
33
34
        if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
35
            throw new RuntimeException("Ce mot de passe n'utilise pas l'algorithme Argon2id.");
36
        }
37
38
        return password_verify($value, $hashedValue);
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    protected function isUsingCorrectAlgorithm(string $hashedValue): bool
45
    {
46
        return $this->info($hashedValue)['algoName'] === 'argon2id';
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    protected function algorithm(): string
53
    {
54
        return PASSWORD_ARGON2ID;
55
    }
56
}
57