Ejemplo n.º 1
0
        public ActionResult AjaxCaptcha()
        {
            this.Response.ContentType = "image/jpeg";
            EnImage enImg = new EnImage();

            enImg.ImgFont  = new Font(FontFamily.GenericSerif, 21, GraphicsUnit.Pixel);
            enImg.ImgColor = EnObject.listColor[0];
            enImg.Height   = 30;
            enImg.Width    = 80;

            string count = this.Request.QueryString["ct"];

            if (string.IsNullOrEmpty(count))
            {
                count = "4";
            }
            if (!new Regex(@"\d{0,127}").IsMatch(count))
            {
                count = "4";
            }

            NCaptcha cca = NCaptcha.GenerateAndDraw(byte.Parse(count), this.Response.OutputStream, enImg, true);

            NModel.EnObject.CaptchaSessionName = cca.SetSessionName;

            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult ImgCaptcha()
        {
            string color = this.Request.QueryString["color"];

            ;
            this.Response.ContentType = "image/jpeg";
            EnImage enImg = new EnImage();

            enImg.ImgFont = new Font(FontFamily.GenericSerif, 30, GraphicsUnit.Pixel);

            try
            {
                enImg.ImgColor = System.Drawing.ColorTranslator.FromHtml("#009B4C");
            }
            catch (Exception ex)
            {
                enImg.ImgColor = EnObject.listColor[7];
            }

            enImg.Height = 40;
            enImg.Width  = 120;

            string count = this.Request.QueryString["ct"];

            if (string.IsNullOrEmpty(count))
            {
                count = "4";
            }
            if (!new Regex(@"\d{0,127}").IsMatch(count))
            {
                count = "4";
            }

            NCaptcha cca = NCaptcha.GenerateAndDraw(byte.Parse(count), this.Response.OutputStream, enImg, true);

            NModel.EnObject.SetCodeValue       = cca.GenerateString;
            NModel.EnObject.CaptchaSessionName = cca.SetSessionName;

            return(View());
        }