public CaptchaResult GetCaptcha(int width, int height) { Guid captchaToken; string captchaAnswer; string requestorIpAddress = String.Empty; if (HttpContext.Current != null) { requestorIpAddress = HttpContext.Current.Request.UserHostAddress; } DataAccess.Captcha.GetNewCaptchaAnswer(requestorIpAddress, out captchaToken, out captchaAnswer); Common.Utility.CaptchaImage captchaImage = new Common.Utility.CaptchaImage(captchaAnswer, width, height); MemoryStream memoryStream = new MemoryStream(); captchaImage.Image.Save(memoryStream, ImageFormat.Jpeg); CaptchaResult returnValue = new CaptchaResult() { CaptchaImage = memoryStream.GetBuffer(), CaptchaToken = captchaToken }; return(returnValue); }
protected void Page_Load(object sender, EventArgs e) { byte[] imageData = null; int width = 200; int height = 100; // Prevent people from slamming this page. lock (_syncObject) { Thread.Sleep(250); } if (string.IsNullOrEmpty(Request.Params["token"]) == false && string.IsNullOrEmpty(Request.Params["width"]) == false && string.IsNullOrEmpty(Request.Params["height"]) == false && Int32.TryParse(Request.Params["width"], out width) == true && Int32.TryParse(Request.Params["height"], out height) == true) { Guid captchaToken = new Guid(Request.Params["token"]); using (CSSDataContext db = new CSSDataContext()) { var captcha = db.Captchas.FirstOrDefault(p => p.Id == captchaToken); if (captcha != null) { ACSSAuth.Common.Utility.CaptchaImage captchaImage = new Common.Utility.CaptchaImage(captcha.Answer, width, height); MemoryStream imageStream = new MemoryStream(); captchaImage.Image.Save(imageStream, ImageFormat.Jpeg); imageData = imageStream.GetBuffer(); } } } if (imageData == null) { imageData = File.ReadAllBytes(Server.MapPath("~/Images/dg_banned.png")); } Response.ContentType = "image/jpeg"; Response.AppendHeader("Content-Length", imageData.Length.ToString()); Response.BinaryWrite(imageData); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { byte[] imageData = null; int width = 200; int height = 100; // Prevent people from slamming this page. lock (_syncObject) { Thread.Sleep(250); } if (string.IsNullOrEmpty(Request.Params["token"]) == false && string.IsNullOrEmpty(Request.Params["width"]) == false && string.IsNullOrEmpty(Request.Params["height"]) == false && Int32.TryParse(Request.Params["width"], out width) == true && Int32.TryParse(Request.Params["height"], out height) == true) { Guid captchaToken = new Guid(Request.Params["token"]); using (CSSDataContext db = new CSSDataContext()) { var captcha = db.Captchas.FirstOrDefault(p => p.Id == captchaToken); if (captcha != null) { Allegiance.CommunitySecuritySystem.Common.Utility.CaptchaImage captchaImage = new Common.Utility.CaptchaImage(captcha.Answer, width, height); MemoryStream imageStream = new MemoryStream(); captchaImage.Image.Save(imageStream, ImageFormat.Jpeg); imageData = imageStream.GetBuffer(); } } } if (imageData == null) imageData = File.ReadAllBytes(Server.MapPath("~/Images/dg_banned.png")); Response.ContentType = "image/jpeg"; Response.AppendHeader("Content-Length", imageData.Length.ToString()); Response.BinaryWrite(imageData); Response.End(); }
public CaptchaResult GetCaptcha(int width, int height) { Guid captchaToken; string captchaAnswer; string requestorIpAddress = String.Empty; if (HttpContext.Current != null) requestorIpAddress = HttpContext.Current.Request.UserHostAddress; DataAccess.Captcha.GetNewCaptchaAnswer(requestorIpAddress, out captchaToken, out captchaAnswer); Common.Utility.CaptchaImage captchaImage = new Common.Utility.CaptchaImage(captchaAnswer, width, height); MemoryStream memoryStream = new MemoryStream(); captchaImage.Image.Save(memoryStream, ImageFormat.Jpeg); CaptchaResult returnValue = new CaptchaResult() { CaptchaImage = memoryStream.GetBuffer(), CaptchaToken = captchaToken }; return returnValue; }