| @@ 14-67 (lines=54) @@ | ||
| 11 | /** |
|
| 12 | * Implements the password hashing algorithm of Invision Power Board (ipb). |
|
| 13 | */ |
|
| 14 | class IpbPassword implements IPassword { |
|
| 15 | ||
| 16 | /** |
|
| 17 | * {@inheritdoc} |
|
| 18 | */ |
|
| 19 | public function hash($password) { |
|
| 20 | $salt = base64_encode(openssl_random_pseudo_bytes(12)); |
|
| 21 | return $this->hashRaw($password, $salt).'$'.$salt; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Hashes a password with a given salt. |
|
| 26 | * |
|
| 27 | * @param string $password The password to hash. |
|
| 28 | * @param string $salt The password salt. |
|
| 29 | * @return string Returns the password hash. |
|
| 30 | */ |
|
| 31 | protected function hashRaw($password, $salt) { |
|
| 32 | $calc_hash = md5(md5($salt).md5($password)); |
|
| 33 | ||
| 34 | return $calc_hash; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * {@inheritdoc} |
|
| 39 | */ |
|
| 40 | public function needsRehash($hash) { |
|
| 41 | return false; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@inheritdoc} |
|
| 46 | */ |
|
| 47 | public function verify($password, $hash) { |
|
| 48 | list($stored_hash, $salt) = $this->splitHash($hash); |
|
| 49 | $calc_hash = $this->hashRaw($password, $salt); |
|
| 50 | return $calc_hash === $stored_hash; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Split the hash into its calculated hash and salt. |
|
| 55 | * |
|
| 56 | * @param string $hash The hash to split. |
|
| 57 | * @return array An array in the form [$hash, $salt]. |
|
| 58 | */ |
|
| 59 | protected function splitHash($hash) { |
|
| 60 | if (strpos($hash, '$') === false) { |
|
| 61 | return [false, false]; |
|
| 62 | } else { |
|
| 63 | $parts = explode('$', $hash, 2); |
|
| 64 | return $parts; |
|
| 65 | } |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 13-66 (lines=54) @@ | ||
| 10 | /** |
|
| 11 | * Implements the password hashing algorithm of Joomla. |
|
| 12 | */ |
|
| 13 | class JoomlaPassword implements IPassword { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * {@inheritdoc} |
|
| 17 | */ |
|
| 18 | public function hash($password) { |
|
| 19 | $salt = base64_encode(openssl_random_pseudo_bytes(12)); |
|
| 20 | return $this->hashRaw($password, $salt).':'.$salt; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Hashes a password with a given salt. |
|
| 25 | * |
|
| 26 | * @param string $password The password to hash. |
|
| 27 | * @param string $salt The password salt. |
|
| 28 | * @return string Returns the password hash. |
|
| 29 | */ |
|
| 30 | protected function hashRaw($password, $salt) { |
|
| 31 | $calc_hash = md5($password.$salt); |
|
| 32 | ||
| 33 | return $calc_hash; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function needsRehash($hash) { |
|
| 40 | return false; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * {@inheritdoc} |
|
| 45 | */ |
|
| 46 | public function verify($password, $hash) { |
|
| 47 | list($stored_hash, $salt) = $this->splitHash($hash); |
|
| 48 | $calc_hash = $this->hashRaw($password, $salt); |
|
| 49 | return $calc_hash === $stored_hash; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Split the hash into its calculated hash and salt. |
|
| 54 | * |
|
| 55 | * @param string $hash The hash to split. |
|
| 56 | * @return array An array in the form [$hash, $salt]. |
|
| 57 | */ |
|
| 58 | protected function splitHash($hash) { |
|
| 59 | if (strpos($hash, ':') === false) { |
|
| 60 | return [false, false]; |
|
| 61 | } else { |
|
| 62 | $parts = explode(':', $hash, 2); |
|
| 63 | return $parts; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 13-66 (lines=54) @@ | ||
| 10 | /** |
|
| 11 | * Implements the password hashing algorithm of Mybb. |
|
| 12 | */ |
|
| 13 | class MybbPassword implements IPassword { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * {@inheritdoc} |
|
| 17 | */ |
|
| 18 | public function hash($password) { |
|
| 19 | $salt = base64_encode(openssl_random_pseudo_bytes(12)); |
|
| 20 | return $this->hashRaw($password, $salt).':'.$salt; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Hashes a password with a given salt. |
|
| 25 | * |
|
| 26 | * @param string $password The password to hash. |
|
| 27 | * @param string $salt The password salt. |
|
| 28 | * @return string Returns the password hash. |
|
| 29 | */ |
|
| 30 | protected function hashRaw($password, $salt) { |
|
| 31 | $calc_hash = md5(md5($salt).$password); |
|
| 32 | ||
| 33 | return $calc_hash; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function needsRehash($hash) { |
|
| 40 | return false; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * {@inheritdoc} |
|
| 45 | */ |
|
| 46 | public function verify($password, $hash) { |
|
| 47 | list($stored_hash, $salt) = $this->splitHash($hash); |
|
| 48 | $calc_hash = $this->hashRaw($password, $salt); |
|
| 49 | return $calc_hash === $stored_hash; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Split the hash into its calculated hash and salt. |
|
| 54 | * |
|
| 55 | * @param string $hash The hash to split. |
|
| 56 | * @return array An array in the form [$hash, $salt]. |
|
| 57 | */ |
|
| 58 | protected function splitHash($hash) { |
|
| 59 | if (strpos($hash, ':') === false) { |
|
| 60 | return [false, false]; |
|
| 61 | } else { |
|
| 62 | $parts = explode(':', $hash, 2); |
|
| 63 | return $parts; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||