-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathHash.php
More file actions
80 lines (67 loc) · 1.83 KB
/
Copy pathHash.php
File metadata and controls
80 lines (67 loc) · 1.83 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace Bow\Security;
class Hash
{
/**
* Allows to have a value and when the hash has failed it returns false.
*
* @param string $value
* @return string|int|null
*/
public static function create(string $value): string|int|null
{
[$hash_method, $options] = static::getHashConfig();
return password_hash($value, $hash_method, $options);
}
/**
* Get the hash configuration
*
* @return array
*/
protected static function getHashConfig(): array
{
$hash_method = config('security.hash_method');
$options = config('security.hash_options');
if (is_null($hash_method) || $hash_method == PASSWORD_BCRYPT) {
$hash_method = PASSWORD_BCRYPT;
}
return [$hash_method, $options];
}
/**
* Allows to have a value and when the hash has failed it returns false.
*
* @param string $value
* @return string|int|null
*/
public static function make(string $value): string|int|null
{
[$hash_method, $options] = static::getHashConfig();
return password_hash($value, $hash_method, $options);
}
/**
* Allows you to check the hash by adding a value
*
* @param string $value
* @param string $hash
* @return bool
*/
public static function check(string $value, string $hash): bool
{
if (strlen($hash) === 0) {
return false;
}
return password_verify($value, $hash);
}
/**
* Allows you to rehash a value.
*
* @param string $hash
* @return bool
*/
public static function needsRehash(string $hash): bool
{
[$hash_method, $options] = static::getHashConfig();
return password_needs_rehash($hash, $hash_method, $options);
}
}