Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Argon2IdHasher
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 make
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 requiresRehash
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Crypt\Hashing;
16
17/**
18 * Pop Crypt Argon2ID hasher
19 *
20 * @category   Pop
21 * @package    Pop\Crypt
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    4.0.0
26 */
27class Argon2IdHasher extends AbstractArgon2Hasher
28{
29
30    /**
31     * Make hashed value (based on the hasher class)
32     *
33     * @param  string $value
34     * @return string
35     */
36    public function make(#[\SensitiveParameter] string $value): string
37    {
38        $options = [
39            'memory_cost' => $this->getMemoryCost(),
40            'time_cost'   => $this->getTimeCost(),
41            'threads'     => $this->getThreads(),
42        ];
43        return $this->createHash($value, PASSWORD_ARGON2ID, $options);
44    }
45
46    /**
47     * Determine if the hashed value requires re-hashing (based on the hasher class)
48     *
49     * @param  string $hashedValue
50     * @return bool
51     */
52    public function requiresRehash(string $hashedValue): bool
53    {
54        $options = [
55            'memory_cost' => $this->getMemoryCost(),
56            'time_cost'   => $this->getTimeCost(),
57            'threads'     => $this->getThreads(),
58        ];
59        return $this->needsRehash($hashedValue, PASSWORD_ARGON2ID, $options);
60    }
61
62}