|
21 | 21 |
|
22 | 22 | namespace OCA\UserSQL\Crypto; |
23 | 23 |
|
24 | | -use OCP\IL10N; |
25 | | - |
26 | | -require_once "Phpass.php"; |
27 | | - |
28 | 24 | /** |
29 | 25 | * Drupal 7 overrides of phpass hash implementation. |
30 | 26 | * |
31 | 27 | * @author BrandonKerr |
| 28 | + * @author Marcin Łojewski <dev@mlojewski.me> |
32 | 29 | */ |
33 | 30 | class Drupal7 extends Phpass |
34 | 31 | { |
35 | | - |
36 | | - /** |
37 | | - * The expected (and maximum) number of characters in a hashed password. |
38 | | - */ |
39 | | - const DRUPAL_HASH_LENGTH = 55; |
| 32 | + /** |
| 33 | + * The expected (and maximum) number of characters in a hashed password. |
| 34 | + */ |
| 35 | + const DRUPAL_HASH_LENGTH = 55; |
40 | 36 |
|
41 | 37 | /** |
42 | | - * @param string $password Password to encrypt. |
43 | | - * @param string $setting Hash settings. |
44 | | - * |
45 | | - * @return string|null Generated hash. Null on invalid settings. |
| 38 | + * @inheritdoc |
46 | 39 | */ |
47 | | - private function crypt($password, $setting) |
| 40 | + protected function crypt($password, $setting) |
48 | 41 | { |
49 | | - $countLog2 = strpos(self::ITOA64, $setting[3]); |
50 | | - if ($countLog2 < 7 || $countLog2 > 30) { |
51 | | - return null; |
52 | | - } |
53 | | - |
54 | | - $count = 1 << $countLog2; |
55 | | - |
56 | | - $salt = substr($setting, 4, 8); |
57 | | - if (strlen($salt) !== 8) { |
58 | | - return null; |
59 | | - } |
60 | | - |
61 | | - $hash = hash('sha512', $salt . $password, true); |
62 | | - do { |
63 | | - $hash = hash('sha512', $hash . $password, true); |
64 | | - } while (--$count); |
65 | | - |
66 | | - $output = substr($setting, 0, 12); |
67 | | - $output .= $this->encode64($hash, strlen($hash)); |
68 | | - |
69 | | - return substr($output, 0, self::DRUPAL_HASH_LENGTH); |
| 42 | + return substr(parent::crypt($password, $setting), 0, self::DRUPAL_HASH_LENGTH); |
70 | 43 | } |
71 | 44 |
|
| 45 | + /** |
| 46 | + * @inheritdoc |
| 47 | + */ |
| 48 | + protected function hash($input) |
| 49 | + { |
| 50 | + return hash('sha512', $input, true); |
| 51 | + } |
72 | 52 |
|
73 | 53 | /** |
74 | 54 | * @inheritdoc |
|
0 commit comments