Delegate base64 encoding for Drupal8 to TPhpass
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 28 Apr 2022 11:54:50 +0000 (13:54 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 28 Apr 2022 11:56:08 +0000 (13:56 +0200)
wcfsetup/install/files/lib/system/user/authentication/password/algorithm/Drupal8.class.php

index 24c441da897e3d2bc33a221b6cfc86ea85d52f79..18963d99924ca2f76b0e3d554698a90ed72fd6ab 100644 (file)
@@ -16,7 +16,7 @@ use wcf\system\user\authentication\password\IPasswordAlgorithm;
  */
 final class Drupal8 implements IPasswordAlgorithm
 {
-    private $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+    use TPhpass;
 
     /**
      * Returns the hashed password, with the given settings.
@@ -49,41 +49,7 @@ final class Drupal8 implements IPasswordAlgorithm
         } while (--$count);
 
         $output = \mb_substr($settings, 0, 12, '8bit');
-        $hash_encode64 = static function ($input, $count, &$itoa64) {
-            $output = '';
-            $i = 0;
-
-            do {
-                $value = \ord($input[$i++]);
-                $output .= $itoa64[$value & 0x3f];
-
-                if ($i < $count) {
-                    $value |= \ord($input[$i]) << 8;
-                }
-
-                $output .= $itoa64[($value >> 6) & 0x3f];
-
-                if ($i++ >= $count) {
-                    break;
-                }
-
-                if ($i < $count) {
-                    $value |= \ord($input[$i]) << 16;
-                }
-
-                $output .= $itoa64[($value >> 12) & 0x3f];
-
-                if ($i++ >= $count) {
-                    break;
-                }
-
-                $output .= $itoa64[($value >> 18) & 0x3f];
-            } while ($i < $count);
-
-            return $output;
-        };
-
-        $output .= $hash_encode64($hash, 64, $this->itoa64);
+        $output .= $this->encode64($hash, 64);
 
         return \mb_substr($output, 0, 55, '8bit');
     }