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

Argon2IdHandler::check()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 11
ccs 0
cts 3
cp 0
crap 20
rs 10
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