You are here

function urllogin_base64dec in urllogin 6

Same name and namespace in other branches
  1. 8 urllogin_security.inc \urllogin_base64dec()
  2. 7 urllogin_security.inc \urllogin_base64dec()
  3. 2.x urllogin_security.inc \urllogin_base64dec()

Converts a base64url encoded string into a pair of integers plus an extra byte

Parameters

$i: First Integer, passed by reference

$j: Second Integer, passed by reference

$x: Extra byte, passed by reference

$urlstr: base64 encoded string with the '=' stripped off the end

Return value

Return TRUE if successful, FALSE if $urlstr was invalid base64url

1 call to urllogin_base64dec()
urllogin_decode in ./urllogin_security.inc
Decodes an encoded url string into a user ID and tests validity. If the uid matches the current one supplied, then it is valid even if link is expired. This is so that the user for whom the link is intended does not get an error message if they are…

File

./urllogin_security.inc, line 141
Include file for urllogin security functions. This module is designed for easy drop-in replacement where an alternative encryption model is required.

Code

function urllogin_base64dec(&$i, &$j, &$x, $urlstr) {
  if (strlen($urlstr) != 12) {

    // do not use drupal_strlen because this is a binary string, not UTF
    return FALSE;

    // URL wrong length
  }

  // modify to use base64url decoding and decode
  if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
    $s = base64_decode(strtr($urlstr, '-_,', '+/='), TRUE);
  }
  else {
    $s = base64_decode(strtr($urlstr, '-_,', '+/='));

    // before PHP 5.2, no STRICT parameter
  }
  if ($s == FALSE) {
    return FALSE;
  }
  $i = ord($s[0]) << 24 | ord($s[1]) << 16 | ord($s[2]) << 8 | ord($s[3]);
  $j = ord($s[4]) << 24 | ord($s[5]) << 16 | ord($s[6]) << 8 | ord($s[7]);
  $x = ord($s[8]);
  return TRUE;
}