function PhpassHashedPasswordBase::base64Encode

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php \Drupal\Core\Password\PhpassHashedPasswordBase::base64Encode()

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.

2 calls to PhpassHashedPasswordBase::base64Encode()
PhpassHashedPasswordBase::crypt in core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php
Hash a password using a secure stretched hash.
PhpassHashedPasswordBase::generateSalt in core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php
Generates a random base 64-encoded salt prefixed with hash settings.

File

core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php, line 96

Class

PhpassHashedPasswordBase
Legacy 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.