Exemplo n.º 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();
        }
Exemplo n.º 2
0
 private string GetCaptchaImageURI()
 {
     if (this.IsWebView)
     {
         return("/CarrotwareCaptcha.axd?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.axd?t=" + DateTime.Now.Ticks);
     }
 }
Exemplo n.º 3
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            var key = CaptchaImage.GetKey();

            output.Write("<div style=\"clear: both;\" id=\"" + this.ClientID + "_wrapper\">\r\n");

            if (!string.IsNullOrEmpty(this.ValidationMessage))
            {
                output.Write("<div");

                if (this.IsValid)
                {
                    output.Write(this.CaptchaIsValidStyle.ToString());
                }
                else
                {
                    output.Write(this.CaptchaIsNotValidStyle.ToString());
                }

                output.Write(" id=\"" + this.ClientID + "_msg\">\r\n");
                output.Write(this.ValidationMessage);
                output.Write("\r\n</div>\r\n");
            }

            string sJSFuncName = "Show_" + this.ClientID;

            output.Write("<div" + this.CaptchaImageBoxStyle.ToString() + "> ");
            output.Write("<a href=\"javascript:" + sJSFuncName + "();\"> <img" + this.CaptchaImageStyle.ToString() + " title=\"" + key + "\" alt=\"" + key + "\" border=\"0\" id=\""
                         + this.ClientID + "_img\" src=\"" + GetCaptchaImageURI() + "\" /> </a> \r\n");

            output.Write("</div>\r\n");
            output.Write("<div" + this.CaptchaInstructionStyle.ToString() + ">" + this.Instructions + " </div>\r\n");
            output.Write("<div" + this.CaptchaTextStyle.ToString() + "><input type=\"text\" id=\"" + this.ClientID + "\" name=\"" + this.UniqueID + "\" value=\"" + HttpUtility.HtmlEncode(this.CaptchaText) + "\" /> </div>\r\n");

            output.Write("\r\n<script  type=\"text/javascript\">\r\n");
            output.Write("\r\nfunction " + sJSFuncName + "(){\r\n");
            if (!string.IsNullOrEmpty(key))
            {
                output.Write("alert('" + key.Substring(0, 3) + "' + '" + key.Substring(3) + "');\r\n");
            }
            else
            {
                output.Write("alert('no code');\r\n");
            }
            output.Write("}\r\n");
            output.Write("</script>\r\n");

            output.Write("\r\n</div>\r\n");
        }
Exemplo n.º 4
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);
        }