Example #1
0
        private void DoCaptcha(HttpContext context)
        {
            Color f = ColorTranslator.FromHtml(CaptchaImage.FGColorDef);
            Color b = ColorTranslator.FromHtml(CaptchaImage.BGColorDef);
            Color n = ColorTranslator.FromHtml(CaptchaImage.NColorDef);

            Bitmap captchaImg = CaptchaImage.GetCaptchaImage(f, b, n);

            if (captchaImg == null)
            {
                context.Response.StatusCode        = 404;
                context.Response.StatusDescription = "Not Found";
                context.ApplicationInstance.CompleteRequest();
                return;
            }

            context.Response.ContentType = "image/x-png";

            using (MemoryStream memStream = new MemoryStream()) {
                captchaImg.Save(memStream, ImageFormat.Png);
                memStream.WriteTo(context.Response.OutputStream);
            }
            context.Response.StatusCode        = 200;
            context.Response.StatusDescription = "OK";
            context.ApplicationInstance.CompleteRequest();

            captchaImg.Dispose();
            context.Response.End();
        }
Example #2
0
 private string GetCaptchaImageURI()
 {
     if (this.IsWebView)
     {
         return("/CarrotwareCaptcha.ashx?t=" + DateTime.Now.Ticks +
                "&fgcolor=" + CaptchaImage.EncodeColor(ColorTranslator.ToHtml(this.ForeColor)) +
                "&bgcolor=" + CaptchaImage.EncodeColor(ColorTranslator.ToHtml(this.BackColor)) +
                "&ncolor=" + CaptchaImage.EncodeColor(ColorTranslator.ToHtml(this.NoiseColor)));
     }
     else
     {
         return("/CarrotwareCaptcha.ashx?t=" + DateTime.Now.Ticks);
     }
 }
Example #3
0
        public bool Validate()
        {
            this.IsValid = CaptchaImage.Validate(this.CaptchaText);

            if (!this.IsValid)
            {
                this.ValidationMessage = this.IsNotValidMessage;
            }
            else
            {
                this.ValidationMessage = this.IsValidMessage;
            }

            return(this.IsValid);
        }