Gdn_CookieIdentity::checkCookie PHP Method

checkCookie() public static method

Validate security of our cookie.
public static checkCookie ( $CookieName, null $CookieHashMethod = null, null $CookieSalt = null ) : boolean
$CookieName
$CookieHashMethod null
$CookieSalt null
return boolean
    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) = $CookieData;
        list($UserID, $Expiration) = self::getCookiePayload($CookieName);
        if ($Expiration < time()) {
            self::deleteCookie($CookieName);
            return false;
        }
        $KeyHash = hash_hmac($CookieHashMethod, $HashKey, $CookieSalt);
        $CheckHash = hash_hmac($CookieHashMethod, $HashKey, $KeyHash);
        if (!hash_equals($CheckHash, $CookieHash)) {
            self::deleteCookie($CookieName);
            return false;
        }
        return true;
    }