1 | <?php |
||
8 | class ExpressionEngineHasher implements HasherContract{ |
||
9 | |||
10 | private $hash_algorithms = array( |
||
11 | 128 => 'sha512', |
||
12 | 64 => 'sha256', |
||
13 | 40 => 'sha1', |
||
14 | 32 => 'md5' |
||
15 | ); |
||
16 | |||
17 | /** |
||
18 | * Default crypt cost factor. |
||
19 | * |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $rounds = 10; |
||
23 | |||
24 | /** |
||
25 | * The size of the hash created by the bcrypt algorithm. |
||
26 | * |
||
27 | * This is used to detect whether a user's password was created by Expression Engine (doesn't support |
||
28 | * bcrypt, or from the newer system). |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $bcrypt_hash_size = 60; |
||
33 | |||
34 | /** |
||
35 | * Hash the given value. |
||
36 | * |
||
37 | * @param string $value |
||
38 | * @param array $options |
||
39 | * @return string |
||
40 | * @throws Exception |
||
41 | */ |
||
42 | 12 | public function make($value, array $options = array()) |
|
72 | |||
73 | /** |
||
74 | * Ensure that a hash doesn't exceed an operatble length. |
||
75 | * |
||
76 | * MD5 collisions usually happen above 1024 bits, so |
||
77 | * we artificially limit their password to reasonable size. |
||
78 | * |
||
79 | * @access private |
||
80 | * @param string $value |
||
81 | * @throws Exception |
||
82 | */ |
||
83 | 12 | private function guardAgainstMd5Collisions($value) |
|
90 | |||
91 | /** |
||
92 | * Generate a new SALT used for hashing the password. |
||
93 | * |
||
94 | * The salt should never be displayed, so any ascii character can be used for higher security. |
||
95 | * |
||
96 | * @param $byte_size |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | public function generateSalt($byte_size = 128) |
|
108 | |||
109 | /** |
||
110 | * Hash a password using Bcrypt. |
||
111 | * |
||
112 | * @param string $value |
||
113 | * @param array $options |
||
114 | * @return string |
||
115 | * @throws Exception |
||
116 | */ |
||
117 | 4 | private function hashUsingBcrypt($value, $options) |
|
130 | |||
131 | /** |
||
132 | * Check the given plain value against a hash. |
||
133 | * |
||
134 | * @param string $value |
||
135 | * @param string $hashedValue |
||
136 | * @param array $options |
||
137 | * @return bool |
||
138 | */ |
||
139 | 7 | public function check($value, $hashedValue, array $options = array()) |
|
157 | |||
158 | /** |
||
159 | * Check if the given hash has been hashed using the given options. |
||
160 | * |
||
161 | * @param string $hashedValue |
||
162 | * @param array $options |
||
163 | * @return bool |
||
164 | */ |
||
165 | 3 | public function needsRehash($hashedValue, array $options = array()) |
|
176 | |||
177 | /** |
||
178 | * Set the default password work factor. |
||
179 | * |
||
180 | * @param int $rounds |
||
181 | * @return $this |
||
182 | */ |
||
183 | 1 | public function setRounds($rounds) |
|
189 | |||
190 | 1 | public function getRounds() |
|
194 | } |
||
195 |