3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $duo = <<< PHP <?php class Duo { const DUO_PREFIX = "TX"; const APP_PREFIX = "APP"; const AUTH_PREFIX = "AUTH"; const DUO_EXPIRE = 300; const APP_EXPIRE = 3600; const IKEY_LEN = 20; const SKEY_LEN = 40; const AKEY_LEN = 40; // if this changes you have to change ERR_AKEY const ERR_USER = 'ERR|The username passed to sign_request() is invalid.'; const ERR_IKEY = 'ERR|The Duo integration key passed to sign_request() is invalid.'; const ERR_SKEY = 'ERR|The Duo secret key passed to sign_request() is invalid.'; const ERR_AKEY = 'ERR|The application secret key passed to sign_request() must be at least 40 characters.'; private static function sign_vals($key, $vals, $prefix, $expire, $time=NULL) { $exp = ($time ? $time : time()) + $expire; $val = $vals . '|' . $exp; $b64 = base64_encode($val); $cookie = $prefix . '|' . $b64; $sig = hash_hmac("sha1", $cookie, $key); return $cookie . '|' . $sig; } private static function parse_vals($key, $val, $prefix, $ikey, $time=NULL) { $ts = ($time ? $time : time()); $parts = explode('|', $val); if (count($parts) !== 3) { return null; } list($u_prefix, $u_b64, $u_sig) = $parts; $sig = hash_hmac("sha1", $u_prefix . '|' . $u_b64, $key); if (hash_hmac("sha1", $sig, $key) !== hash_hmac("sha1", $u_sig, $key)) { return null; } if ($u_prefix !== $prefix) { return null; } $cookie_parts = explode('|', base64_decode($u_b64)); if (count($cookie_parts) !== 3) { return null; } list($user, $u_ikey, $exp) = $cookie_parts; if ($u_ikey !== $ikey) { return null; } if ($ts >= intval($exp)) { return null; } return $user; } public static function signRequest($ikey, $skey, $akey, $username, $time=NULL) { if (!isset($username) || strlen($username) === 0) { return self::ERR_USER; } if (strpos($username, '|') !== FALSE) { return self::ERR_USER; } if (!isset($ikey) || strlen($ikey) !== self::IKEY_LEN) { return self::ERR_IKEY; } if (!isset($skey) || strlen($skey) !== self::SKEY_LEN) { return self::ERR_SKEY; } if (!isset($akey) || strlen($akey) < self::AKEY_LEN) { return self::ERR_AKEY; } $vals = $username . '|' . $ikey; $duo_sig = self::sign_vals($skey, $vals, self::DUO_PREFIX, self::DUO_EXPIRE, $time); $app_sig = self::sign_vals($akey, $vals, self::APP_PREFIX, self::APP_EXPIRE, $time); return $duo_sig . ':' . $app_sig; } public static function verifyResponse($ikey, $skey, $akey, $sig_response, $time=NULL) { list($auth_sig, $app_sig) = explode(':', $sig_response); $auth_user = self::parse_vals($skey, $auth_sig, self::AUTH_PREFIX, $ikey, $time); $app_user = self::parse_vals($akey, $app_sig, self::APP_PREFIX, $ikey, $time); if ($auth_user !== $app_user) { return null; } return $auth_user; } } ?> PHP; echo md5($duo);
Output for 7.0.0 - 7.2.0
Notice: Undefined variable: key in /in/5CTp5 on line 23 Notice: Undefined variable: vals in /in/5CTp5 on line 23 Notice: Undefined variable: prefix in /in/5CTp5 on line 23 Notice: Undefined variable: expire in /in/5CTp5 on line 23 Notice: Undefined variable: time in /in/5CTp5 on line 23 Notice: Undefined variable: exp in /in/5CTp5 on line 24 Notice: Undefined variable: time in /in/5CTp5 on line 24 Notice: Undefined variable: time in /in/5CTp5 on line 24 Notice: Undefined variable: expire in /in/5CTp5 on line 24 Notice: Undefined variable: val in /in/5CTp5 on line 25 Notice: Undefined variable: vals in /in/5CTp5 on line 25 Notice: Undefined variable: exp in /in/5CTp5 on line 25 Notice: Undefined variable: b64 in /in/5CTp5 on line 26 Notice: Undefined variable: val in /in/5CTp5 on line 26 Notice: Undefined variable: cookie in /in/5CTp5 on line 27 Notice: Undefined variable: prefix in /in/5CTp5 on line 27 Notice: Undefined variable: b64 in /in/5CTp5 on line 27 Notice: Undefined variable: sig in /in/5CTp5 on line 29 Notice: Undefined variable: cookie in /in/5CTp5 on line 29 Notice: Undefined variable: key in /in/5CTp5 on line 29 Notice: Undefined variable: cookie in /in/5CTp5 on line 30 Notice: Undefined variable: sig in /in/5CTp5 on line 30 Notice: Undefined variable: key in /in/5CTp5 on line 33 Notice: Undefined variable: val in /in/5CTp5 on line 33 Notice: Undefined variable: prefix in /in/5CTp5 on line 33 Notice: Undefined variable: ikey in /in/5CTp5 on line 33 Notice: Undefined variable: time in /in/5CTp5 on line 33 Notice: Undefined variable: ts in /in/5CTp5 on line 34 Notice: Undefined variable: time in /in/5CTp5 on line 34 Notice: Undefined variable: time in /in/5CTp5 on line 34 Notice: Undefined variable: parts in /in/5CTp5 on line 36 Notice: Undefined variable: val in /in/5CTp5 on line 36 Notice: Undefined variable: parts in /in/5CTp5 on line 37 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 40 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 40 Notice: Undefined variable: u_sig in /in/5CTp5 on line 40 Notice: Undefined variable: parts in /in/5CTp5 on line 40 Notice: Undefined variable: sig in /in/5CTp5 on line 42 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 42 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 42 Notice: Undefined variable: key in /in/5CTp5 on line 42 Notice: Undefined variable: sig in /in/5CTp5 on line 43 Notice: Undefined variable: key in /in/5CTp5 on line 43 Notice: Undefined variable: u_sig in /in/5CTp5 on line 43 Notice: Undefined variable: key in /in/5CTp5 on line 43 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 47 Notice: Undefined variable: prefix in /in/5CTp5 on line 47 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 51 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 51 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 52 Notice: Undefined variable: user in /in/5CTp5 on line 55 Notice: Undefined variable: u_ikey in /in/5CTp5 on line 55 Notice: Undefined variable: exp in /in/5CTp5 on line 55 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 55 Notice: Undefined variable: u_ikey in /in/5CTp5 on line 57 Notice: Undefined variable: ikey in /in/5CTp5 on line 57 Notice: Undefined variable: ts in /in/5CTp5 on line 60 Notice: Undefined variable: exp in /in/5CTp5 on line 60 Notice: Undefined variable: user in /in/5CTp5 on line 64 Notice: Undefined variable: ikey in /in/5CTp5 on line 67 Notice: Undefined variable: skey in /in/5CTp5 on line 67 Notice: Undefined variable: akey in /in/5CTp5 on line 67 Notice: Undefined variable: username in /in/5CTp5 on line 67 Notice: Undefined variable: time in /in/5CTp5 on line 67 Notice: Undefined variable: username in /in/5CTp5 on line 68 Notice: Undefined variable: username in /in/5CTp5 on line 68 Notice: Undefined variable: username in /in/5CTp5 on line 71 Notice: Undefined variable: ikey in /in/5CTp5 on line 74 Notice: Undefined variable: ikey in /in/5CTp5 on line 74 Notice: Undefined variable: skey in /in/5CTp5 on line 77 Notice: Undefined variable: skey in /in/5CTp5 on line 77 Notice: Undefined variable: akey in /in/5CTp5 on line 80 Notice: Undefined variable: akey in /in/5CTp5 on line 80 Notice: Undefined variable: vals in /in/5CTp5 on line 84 Notice: Undefined variable: username in /in/5CTp5 on line 84 Notice: Undefined variable: ikey in /in/5CTp5 on line 84 Notice: Undefined variable: duo_sig in /in/5CTp5 on line 86 Notice: Undefined variable: skey in /in/5CTp5 on line 86 Notice: Undefined variable: vals in /in/5CTp5 on line 86 Notice: Undefined variable: time in /in/5CTp5 on line 86 Notice: Undefined variable: app_sig in /in/5CTp5 on line 87 Notice: Undefined variable: akey in /in/5CTp5 on line 87 Notice: Undefined variable: vals in /in/5CTp5 on line 87 Notice: Undefined variable: time in /in/5CTp5 on line 87 Notice: Undefined variable: duo_sig in /in/5CTp5 on line 89 Notice: Undefined variable: app_sig in /in/5CTp5 on line 89 Notice: Undefined variable: ikey in /in/5CTp5 on line 92 Notice: Undefined variable: skey in /in/5CTp5 on line 92 Notice: Undefined variable: akey in /in/5CTp5 on line 92 Notice: Undefined variable: sig_response in /in/5CTp5 on line 92 Notice: Undefined variable: time in /in/5CTp5 on line 92 Notice: Undefined variable: auth_sig in /in/5CTp5 on line 93 Notice: Undefined variable: app_sig in /in/5CTp5 on line 93 Notice: Undefined variable: sig_response in /in/5CTp5 on line 93 Notice: Undefined variable: auth_user in /in/5CTp5 on line 95 Notice: Undefined variable: skey in /in/5CTp5 on line 95 Notice: Undefined variable: auth_sig in /in/5CTp5 on line 95 Notice: Undefined variable: ikey in /in/5CTp5 on line 95 Notice: Undefined variable: time in /in/5CTp5 on line 95 Notice: Undefined variable: app_user in /in/5CTp5 on line 96 Notice: Undefined variable: akey in /in/5CTp5 on line 96 Notice: Undefined variable: app_sig in /in/5CTp5 on line 96 Notice: Undefined variable: ikey in /in/5CTp5 on line 96 Notice: Undefined variable: time in /in/5CTp5 on line 96 Notice: Undefined variable: auth_user in /in/5CTp5 on line 98 Notice: Undefined variable: app_user in /in/5CTp5 on line 98 Notice: Undefined variable: auth_user in /in/5CTp5 on line 102 89939b2136defa0cd0331b6453821a11
Output for 5.3.20 - 5.6.28
Notice: Undefined variable: key in /in/5CTp5 on line 23 Notice: Undefined variable: vals in /in/5CTp5 on line 23 Notice: Undefined variable: prefix in /in/5CTp5 on line 23 Notice: Undefined variable: expire in /in/5CTp5 on line 23 Notice: Undefined variable: time in /in/5CTp5 on line 24 Notice: Undefined variable: exp in /in/5CTp5 on line 24 Notice: Undefined variable: time in /in/5CTp5 on line 24 Notice: Undefined variable: time in /in/5CTp5 on line 24 Notice: Undefined variable: expire in /in/5CTp5 on line 25 Notice: Undefined variable: val in /in/5CTp5 on line 25 Notice: Undefined variable: vals in /in/5CTp5 on line 25 Notice: Undefined variable: exp in /in/5CTp5 on line 26 Notice: Undefined variable: b64 in /in/5CTp5 on line 26 Notice: Undefined variable: val in /in/5CTp5 on line 27 Notice: Undefined variable: cookie in /in/5CTp5 on line 27 Notice: Undefined variable: prefix in /in/5CTp5 on line 27 Notice: Undefined variable: b64 in /in/5CTp5 on line 29 Notice: Undefined variable: sig in /in/5CTp5 on line 29 Notice: Undefined variable: cookie in /in/5CTp5 on line 29 Notice: Undefined variable: key in /in/5CTp5 on line 30 Notice: Undefined variable: cookie in /in/5CTp5 on line 30 Notice: Undefined variable: sig in /in/5CTp5 on line 33 Notice: Undefined variable: key in /in/5CTp5 on line 33 Notice: Undefined variable: val in /in/5CTp5 on line 33 Notice: Undefined variable: prefix in /in/5CTp5 on line 33 Notice: Undefined variable: ikey in /in/5CTp5 on line 33 Notice: Undefined variable: time in /in/5CTp5 on line 34 Notice: Undefined variable: ts in /in/5CTp5 on line 34 Notice: Undefined variable: time in /in/5CTp5 on line 34 Notice: Undefined variable: time in /in/5CTp5 on line 36 Notice: Undefined variable: parts in /in/5CTp5 on line 36 Notice: Undefined variable: val in /in/5CTp5 on line 37 Notice: Undefined variable: parts in /in/5CTp5 on line 40 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 40 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 40 Notice: Undefined variable: u_sig in /in/5CTp5 on line 40 Notice: Undefined variable: parts in /in/5CTp5 on line 42 Notice: Undefined variable: sig in /in/5CTp5 on line 42 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 42 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 42 Notice: Undefined variable: key in /in/5CTp5 on line 43 Notice: Undefined variable: sig in /in/5CTp5 on line 43 Notice: Undefined variable: key in /in/5CTp5 on line 43 Notice: Undefined variable: u_sig in /in/5CTp5 on line 43 Notice: Undefined variable: key in /in/5CTp5 on line 47 Notice: Undefined variable: u_prefix in /in/5CTp5 on line 47 Notice: Undefined variable: prefix in /in/5CTp5 on line 51 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 51 Notice: Undefined variable: u_b64 in /in/5CTp5 on line 52 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 55 Notice: Undefined variable: user in /in/5CTp5 on line 55 Notice: Undefined variable: u_ikey in /in/5CTp5 on line 55 Notice: Undefined variable: exp in /in/5CTp5 on line 55 Notice: Undefined variable: cookie_parts in /in/5CTp5 on line 57 Notice: Undefined variable: u_ikey in /in/5CTp5 on line 57 Notice: Undefined variable: ikey in /in/5CTp5 on line 60 Notice: Undefined variable: ts in /in/5CTp5 on line 60 Notice: Undefined variable: exp in /in/5CTp5 on line 64 Notice: Undefined variable: user in /in/5CTp5 on line 67 Notice: Undefined variable: ikey in /in/5CTp5 on line 67 Notice: Undefined variable: skey in /in/5CTp5 on line 67 Notice: Undefined variable: akey in /in/5CTp5 on line 67 Notice: Undefined variable: username in /in/5CTp5 on line 67 Notice: Undefined variable: time in /in/5CTp5 on line 68 Notice: Undefined variable: username in /in/5CTp5 on line 68 Notice: Undefined variable: username in /in/5CTp5 on line 71 Notice: Undefined variable: username in /in/5CTp5 on line 74 Notice: Undefined variable: ikey in /in/5CTp5 on line 74 Notice: Undefined variable: ikey in /in/5CTp5 on line 77 Notice: Undefined variable: skey in /in/5CTp5 on line 77 Notice: Undefined variable: skey in /in/5CTp5 on line 80 Notice: Undefined variable: akey in /in/5CTp5 on line 80 Notice: Undefined variable: akey in /in/5CTp5 on line 84 Notice: Undefined variable: vals in /in/5CTp5 on line 84 Notice: Undefined variable: username in /in/5CTp5 on line 84 Notice: Undefined variable: ikey in /in/5CTp5 on line 86 Notice: Undefined variable: duo_sig in /in/5CTp5 on line 86 Notice: Undefined variable: skey in /in/5CTp5 on line 86 Notice: Undefined variable: vals in /in/5CTp5 on line 86 Notice: Undefined variable: time in /in/5CTp5 on line 87 Notice: Undefined variable: app_sig in /in/5CTp5 on line 87 Notice: Undefined variable: akey in /in/5CTp5 on line 87 Notice: Undefined variable: vals in /in/5CTp5 on line 87 Notice: Undefined variable: time in /in/5CTp5 on line 89 Notice: Undefined variable: duo_sig in /in/5CTp5 on line 89 Notice: Undefined variable: app_sig in /in/5CTp5 on line 92 Notice: Undefined variable: ikey in /in/5CTp5 on line 92 Notice: Undefined variable: skey in /in/5CTp5 on line 92 Notice: Undefined variable: akey in /in/5CTp5 on line 92 Notice: Undefined variable: sig_response in /in/5CTp5 on line 92 Notice: Undefined variable: time in /in/5CTp5 on line 93 Notice: Undefined variable: auth_sig in /in/5CTp5 on line 93 Notice: Undefined variable: app_sig in /in/5CTp5 on line 93 Notice: Undefined variable: sig_response in /in/5CTp5 on line 95 Notice: Undefined variable: auth_user in /in/5CTp5 on line 95 Notice: Undefined variable: skey in /in/5CTp5 on line 95 Notice: Undefined variable: auth_sig in /in/5CTp5 on line 95 Notice: Undefined variable: ikey in /in/5CTp5 on line 95 Notice: Undefined variable: time in /in/5CTp5 on line 96 Notice: Undefined variable: app_user in /in/5CTp5 on line 96 Notice: Undefined variable: akey in /in/5CTp5 on line 96 Notice: Undefined variable: app_sig in /in/5CTp5 on line 96 Notice: Undefined variable: ikey in /in/5CTp5 on line 96 Notice: Undefined variable: time in /in/5CTp5 on line 98 Notice: Undefined variable: auth_user in /in/5CTp5 on line 98 Notice: Undefined variable: app_user in /in/5CTp5 on line 102 Notice: Undefined variable: auth_user in /in/5CTp5 on line 106 89939b2136defa0cd0331b6453821a11