Ejemplo n.º 1
0
        /// <summary>
        ///     英文字母 + 数字
        /// </summary>
        /// <param name="context">httpcontext</param>
        /// <param name="sessionKey">保存运算值的SESSION的KEY</param>
        /// <param name="fontSize">字体长度</param>
        /// <param name="imgWidth">图片长度</param>
        /// <param name="imgHeiht">图片高度</param>
        /// <param name="stainLenght">噪音点长度</param>
        /// <param name="codeLenght">随机码长度</param>
        public static void Alphabet(HttpContext context, string sessionKey, int codeLenght = 4, int fontSize = 12, int imgWidth = 60, int imgHeiht = 20, int stainLenght = 30)
        {
            var code = string.Empty;

            while (string.IsNullOrWhiteSpace(code) || code.Length != codeLenght)
            {
                code = Guid.NewGuid().ToString().Substring(0, codeLenght);
            }

            Cookies.Set(sessionKey, code);
            ResponseImage(context, code, Color.White, fontSize, imgWidth, imgHeiht, stainLenght);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     检测验证码是否正确
        /// </summary>
        /// <param name="sessionKey">保存到session的key</param>
        /// <param name="code">用户输入的验证码</param>
        public static bool Check(string sessionKey, string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(false);
            }

            var verifyCode = Cookies.Get(sessionKey);

            Cookies.Set(sessionKey, Rand.GetRandom(10000, 99999));

            return(code.Trim().IsEquals(verifyCode));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     算术运算验证
        /// </summary>
        /// <param name="context">httpcontext</param>
        /// <param name="sessionKey">保存运算值的SESSION的KEY</param>
        /// <param name="fontSize">字体长度</param>
        /// <param name="imgWidth">图片长度</param>
        /// <param name="imgHeiht">图片高度</param>
        /// <param name="stainLenght">噪音点长度</param>
        public static void Arithmetic(HttpContext context, string sessionKey, int fontSize = 11, int imgWidth = 65, int imgHeiht = 23, int stainLenght = 10)
        {
            string expression = null;
            var    rnd        = new Random();
            // 生成3个10以内的整数,用来运算
            var op1    = rnd.Next(0, 20);
            var op2    = rnd.Next(0, 50);
            var result = 0;


            while (op1 > op2)
            {
                op1 = rnd.Next(0, 20);
                op2 = rnd.Next(0, 10);
            }

            // 随机组合运算顺序,只做 + 运算
            switch (rnd.Next(0, 2))
            {
            case 0:
            {
                result     = op1 + op2;
                expression = string.Format("{0} + {1} = ?", op1, op2);
                break;
            }

            case 1:
            {
                result     = op2 - op1;
                expression = string.Format("{0} + ? = {1}", op1, op2);
                break;
            }

            case 2:
            {
                result     = op2 - op1;
                expression = string.Format("? + {0} = {1}", op1, op2);
                break;
            }
            }
            Cookies.Set(sessionKey, result.ToString());
            ResponseImage(context, expression, Color.White, fontSize, imgWidth, imgHeiht, stainLenght);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 记住用户最后一次访问地址
 /// </summary>
 public static void RememberUrl()
 {
     Cookies.Set(SystemConfigs.ConfigInfo.Cookies_CallBack_Url, Req.GetUrl());
 }