/// <summary> /// Verify cookie. /// </summary> /// <param name="cookieValue">Cookie value.</param> /// <param name="authArea">Authenticate area.</param> /// <param name="username">Username.</param> /// <param name="expiredDate">Expired date.</param> /// <returns></returns> public static bool VerifyCookie(string cookieValue, string authArea, out string username, out DateTime expiredDate) { username = null; expiredDate = DateTime.MinValue; byte[] data; try { data = HttpServerUtility.UrlTokenDecode(cookieValue); BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(data); ComBoostCookiesToken token = (ComBoostCookiesToken)formatter.Deserialize(stream); stream.Dispose(); if (token.Signature.Length != 20) { return(false); } if (token.ExpiredDate < DateTime.Now) { return(false); } if (token.Username == null) { return(false); } if (authArea == null) { data = token.GetTokenData(); } else { data = token.GetTokenData().Concat(Encoding.UTF8.GetBytes(authArea)).ToArray(); } if (!VerifyToken(data, token.Salt, token.Signature)) { return(false); } username = token.Username; expiredDate = token.ExpiredDate; return(true); } catch { return(false); } }