-
Notifications
You must be signed in to change notification settings - Fork 5
/
SodiumHasher.php
62 lines (56 loc) · 1.5 KB
/
SodiumHasher.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
53
54
55
56
57
58
59
60
61
62
<?php
namespace scrothers\laravelsodium;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class SodiumHasher implements HasherContract
{
/**
* Check if the given hash has been hashed using the given options.
*
* @param string $unusedHashedValue
* @param array $unusedOptions
*
* @return bool
*/
public function needsRehash($unusedHashedValue, array $unusedOptions = [])
{
return false;
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
*
* @throws \RuntimeException
*
* @return string
* @return string
*/
public function make($value, array $options = [])
{
// Check if we're making a slow password
if (array_key_exists('slow', $options)) {
if (is_bool($options['slow'])) {
$slowPassword = $options['slow'];
} else {
$slowPassword = false;
}
} else {
$slowPassword = false;
}
return SodiumLibrary::hashPassword($value, $slowPassword);
}
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param array $unusedOptions Options are not used for Sodium password verification
*
* @return bool
*/
public function check($value, $hashedValue, array $unusedOptions = [])
{
return SodiumLibrary::checkPassword($value, $hashedValue);
}
}