Exemplo n.º 1
0
        /// <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));
        }