protected function PhpassHashedPassword::base64Encode

protected PhpassHashedPassword::base64Encode($input, $count)

Encodes bytes into printable base 64 using the *nix standard from crypt().

Parameters

string $input: The string containing bytes to encode.

int $count: The number of characters (bytes) to encode.

Return value

string Encoded string.

File

core/lib/Drupal/Core/Password/PhpassHashedPassword.php, line 66

Class

PhpassHashedPassword
Secure password hashing functions based on the Portable PHP password hashing framework.

Namespace

Drupal\Core\Password

Code

protected function base64Encode($input, $count) {
  $output = '';
  $i = 0;
  do {
    $value = ord($input[$i++]);
    $output .= static::$ITOA64[$value & 0x3f];
    if ($i < $count) {
      $value |= ord($input[$i]) << 8;
    }
    $output .= static::$ITOA64[($value >> 6) & 0x3f];
    if ($i++ >= $count) {
      break;
    }
    if ($i < $count) {
      $value |= ord($input[$i]) << 16;
    }
    $output .= static::$ITOA64[($value >> 12) & 0x3f];
    if ($i++ >= $count) {
      break;
    }
    $output .= static::$ITOA64[($value >> 18) & 0x3f];
  } while ($i < $count);

  return $output;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Password!PhpassHashedPassword.php/function/PhpassHashedPassword::base64Encode/8.1.x