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

Parameters

$input: The string containing bytes to encode.

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

Return value

Encoded string

2 calls to _password_base64_encode()
_password_crypt in includes/password.inc
Hash a password using a secure stretched hash.
_password_generate_salt in includes/password.inc
Generates a random base 64-encoded salt prefixed with settings for the hash.

File

includes/password.inc, line 56
Secure password hashing functions for user authentication.

Code

function _password_base64_encode($input, $count) {
  $output = '';
  $i = 0;
  $itoa64 = _password_itoa64();
  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;
}