From: Tim Düsterhus Date: Thu, 28 Apr 2022 11:50:43 +0000 (+0200) Subject: Add TPhpass::encode64() X-Git-Tag: 5.5.0_Alpha_5~8^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=33e3e350b8d0d7862883856a9d7d1f221a891782;p=GitHub%2FWoltLab%2FWCF.git Add TPhpass::encode64() --- diff --git a/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/TPhpass.class.php b/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/TPhpass.class.php index 87a3ca8d79..a816c16bf5 100644 --- a/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/TPhpass.class.php +++ b/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/TPhpass.class.php @@ -48,41 +48,45 @@ trait TPhpass } while (--$count); $output = \mb_substr($settings, 0, 12, '8bit'); - $hash_encode64 = static function ($input, $count, &$itoa64) { - $output = ''; - $i = 0; + $output .= $this->encode64($hash, 16); - do { - $value = \ord($input[$i++]); - $output .= $itoa64[$value & 0x3f]; + return $output; + } - if ($i < $count) { - $value |= \ord($input[$i]) << 8; - } + /** + * Encodes $count characters from $input with PHPASS' custom base64 encoder. + */ + private function encode64(string $input, int $count): string + { + $output = ''; + $i = 0; - $output .= $itoa64[($value >> 6) & 0x3f]; + do { + $value = \ord($input[$i++]); + $output .= $this->itoa64[$value & 0x3f]; - if ($i++ >= $count) { - break; - } + if ($i < $count) { + $value |= \ord($input[$i]) << 8; + } - if ($i < $count) { - $value |= \ord($input[$i]) << 16; - } + $output .= $this->itoa64[($value >> 6) & 0x3f]; - $output .= $itoa64[($value >> 12) & 0x3f]; + if ($i++ >= $count) { + break; + } - if ($i++ >= $count) { - break; - } + if ($i < $count) { + $value |= \ord($input[$i]) << 16; + } - $output .= $itoa64[($value >> 18) & 0x3f]; - } while ($i < $count); + $output .= $this->itoa64[($value >> 12) & 0x3f]; - return $output; - }; + if ($i++ >= $count) { + break; + } - $output .= $hash_encode64($hash, 16, $this->itoa64); + $output .= $this->itoa64[($value >> 18) & 0x3f]; + } while ($i < $count); return $output; }