/// <summary> /// 验证用户输入的验证码是否正确 /// </summary> /// <param name="code">用户输入的验证码</param> /// <returns>用户输入的验证码是否正确</returns> public static Boolean VerifyCheckCode(String code) { if (String.IsNullOrEmpty(code)) { throw new InvalidInputException("The verification code can not be NULL!"); } HttpCookie checkCode = CheckCodeStatus.GetCheckCodeCookie(); if (checkCode == null || String.IsNullOrEmpty(checkCode.Value)) { throw new InvalidInputException(String.Format("The verification codes are only valid for a maximum of {0} seconds!", ConfigurationManager.CheckCodeTimeout.ToString())); } String hashed = CheckCodeStatus.EncryptCode(code); CheckCodeStatus.RemoveCheckCode(); return(String.Equals(checkCode.Value, hashed, StringComparison.Ordinal)); }
/// <summary> /// 设置验证码信息 /// </summary> /// <param name="checkCode">验证码信息</param> public static void SetCheckCode(String checkCode) { String hashed = CheckCodeStatus.EncryptCode(checkCode); Cookies.SetValue(CHECK_CODE_COOKIE_NAME, hashed, true, DateTime.Now.AddSeconds(ConfigurationManager.CheckCodeTimeout)); }