Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | class Mlf2PasswordHasher extends AbstractPasswordHasher |
||
23 | { |
||
24 | /** |
||
25 | * {@inheritDoc} |
||
26 | */ |
||
27 | public function hash($password) |
||
28 | { |
||
29 | // compare to includes/functions.inc.php generate_pw_hash() mlf 2.3 |
||
30 | $salt = self::_generateRandomString(10); |
||
31 | $saltedHash = sha1($password . $salt); |
||
32 | $hashWithSalt = $saltedHash . $salt; |
||
33 | |||
34 | return $hashWithSalt; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Generate random string |
||
39 | * |
||
40 | * @param int $maxLength maximum length |
||
41 | * @return string |
||
42 | */ |
||
43 | protected static function _generateRandomString($maxLength = null) |
||
44 | { |
||
45 | $string = Security::hash(Text::uuid()); |
||
46 | if ($maxLength) { |
||
|
|||
47 | $string = substr($string, 0, $maxLength); |
||
48 | } |
||
49 | |||
50 | return $string; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * {@inheritDoc} |
||
55 | */ |
||
56 | public function check($password, $hash) |
||
67 | } |
||
68 | } |
||
69 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: