public function CheckCookie() { if (empty($_COOKIE[$this->_CookieName])) return FALSE; $CookieHashMethod = C('Garden.Cookie.HashMethod'); $CookieSalt = C('Garden.Cookie.Salt'); $CookieData = explode('|', $_COOKIE[$this->_CookieName]); if (count($CookieData) < 4) { $this->DeleteCookie(); return FALSE; } list($Key, $CookieHash, $Time, $CookiePayload) = $CookieData; $KeyHash = self::_Hash($Key, $CookieHashMethod, $CookieSalt); $GeneratedHash = self::_HashHMAC($CookieHashMethod, $Key, $KeyHash); if (!CompareHashDigest($CookieHash, $GeneratedHash)) return $this->DeleteCookie(); return TRUE; }
public static function CheckCookie($CookieName, $CookieHashMethod = NULL, $CookieSalt = NULL) { if (empty($_COOKIE[$CookieName])) { return FALSE; } if (is_null($CookieHashMethod)) { $CookieHashMethod = Gdn::Config('Garden.Cookie.HashMethod'); } if (is_null($CookieSalt)) { $CookieSalt = Gdn::Config('Garden.Cookie.Salt'); } $CookieData = explode('|', $_COOKIE[$CookieName]); if (count($CookieData) < 5) { self::DeleteCookie($CookieName); return FALSE; } list($HashKey, $CookieHash, $Time, $UserID, $Expiration) = $CookieData; if ($Expiration < time() && $Expiration != 0) { self::DeleteCookie($CookieName); return FALSE; } $Key = self::_Hash($HashKey, $CookieHashMethod, $CookieSalt); $GeneratedHash = self::_HashHMAC($CookieHashMethod, $HashKey, $Key); if (!CompareHashDigest($CookieHash, $GeneratedHash)) { self::DeleteCookie($CookieName); return FALSE; } return TRUE; }
/** * * * @param $CookieName * @param null $CookieHashMethod * @param null $CookieSalt * @return bool */ public static function checkCookie($CookieName, $CookieHashMethod = null, $CookieSalt = null) { if (empty($_COOKIE[$CookieName])) { return false; } if (is_null($CookieHashMethod)) { $CookieHashMethod = Gdn::config('Garden.Cookie.HashMethod'); } if (is_null($CookieSalt)) { $CookieSalt = Gdn::config('Garden.Cookie.Salt'); } $CookieData = explode('|', $_COOKIE[$CookieName]); if (count($CookieData) < 5) { self::deleteCookie($CookieName); return false; } list($HashKey, $CookieHash, $Time, $UserID, $PayloadExpires) = $CookieData; if ($PayloadExpires < time() && $PayloadExpires != 0) { self::deleteCookie($CookieName); return false; } $KeyHash = self::_hash($HashKey, $CookieHashMethod, $CookieSalt); $CheckHash = self::_hashHMAC($CookieHashMethod, $HashKey, $KeyHash); if (!CompareHashDigest($CookieHash, $CheckHash)) { self::deleteCookie($CookieName); return false; } return true; }