31) ? static::BF : $count; $base64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $i = 0; $input = Random::generate(16); $output = ''; do { $c1 = ord($input[$i++]); $output .= $base64[$c1 >> 2]; $c1 = ($c1 & 0x03) << 4; if ($i >= 16) { $output .= $base64[$c1]; break; } $c2 = ord($input[$i++]); $c1 |= $c2 >> 4; $output .= $base64[$c1]; $c1 = ($c2 & 0x0f) << 2; $c2 = ord($input[$i++]); $c1 |= $c2 >> 6; $output .= $base64[$c1]; $output .= $base64[$c2 & 0x3f]; } while (1); $result = '$2a$'; $result .= chr(ord('0') + $count / static::BF); $result .= chr(ord('0') + $count % static::BF); $result .= '$' . $output; return $result; } /** * Generates an Extended DES salt for use in `lithium\security\Password::hash()`. * * @param integer $count The base-2 logarithm of the iteration count. Defaults to `18`. Can be * `1` to `24`. 1 will be stripped from the non-log value, e.g. 2^18 - 1, to * ensure we don't use a weak DES key. * @return string The XDES salt. */ protected static function _generateSaltXdes($count = null) { $count = (integer) $count; $count = ($count < 1 || $count > 24) ? static::XDES : $count; $count = (1 << $count) - 1; $base64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $output = '_' . $base64[$count & 0x3f] . $base64[($count >> 6) & 0x3f]; $output .= $base64[($count >> 12) & 0x3f] . $base64[($count >> 18) & 0x3f]; $output .= Random::generate(3, ['encode' => Random::ENCODE_BASE_64]); return $output; } /** * Generates an MD5 salt for use in `lithium\security\Password::hash()`. * * @return string The MD5 salt. */ protected static function _generateSaltMd5() { return '$1$' . Random::generate(6, ['encode' => Random::ENCODE_BASE_64]); } } ?>