-
Notifications
You must be signed in to change notification settings - Fork 4
/
Argon2IdHasher.php
52 lines (45 loc) · 1.22 KB
/
Argon2IdHasher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Illuminate\Hashing;
use RuntimeException;
class Argon2IdHasher extends ArgonHasher
{
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string|null $hashedValue
* @param array $options
* @return bool
*
* @throws \RuntimeException
*/
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2id algorithm.');
}
return password_verify($value, $hashedValue);
}
/**
* Verify the hashed value's algorithm.
*
* @param string $hashedValue
* @return bool
*/
protected function isUsingCorrectAlgorithm($hashedValue)
{
return $this->info($hashedValue)['algoName'] === 'argon2id';
}
/**
* Get the algorithm that should be used for hashing.
*
* @return int
*/
protected function algorithm()
{
return PASSWORD_ARGON2ID;
}
}