public FileResult Captcha() { int Width = 200; int Height = 50; if (Request["w"] != null) { if (!int.TryParse(Request["w"], out Width)) { Width = 200; } } if (Request["h"] != null) { if (!int.TryParse(Request["h"], out Height)) { Height = 50; } } CaptchaImage ci = new CaptchaImage(Width, Height); ImageConverter converter = new ImageConverter(); var data = (byte[])converter.ConvertTo(ci.Image, typeof(byte[])); ci.Dispose(); return(File(data, "image/jpeg", "Captcha.jpeg")); }
public void ProcessRequest(HttpContext context) { int width = 200; int height = 30; try { width = Convert.ToInt32(context.Request.QueryString["w"]); height = Convert.ToInt32(context.Request.QueryString["h"]); } catch (Exception) { // Nothing } // 从 Session 中读取验证码,并创建图片 CaptchaImage ci = new CaptchaImage(context.Session["CaptchaImageText"].ToString(), width, height, "Consolas"); // 输出图片 context.Response.Clear(); context.Response.ContentType = "image/jpeg"; ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg); ci.Dispose(); }
public ActionResult GetCaptchaImage() { LoginCacheItem loginCacheItem = GetCachedLoginAttempt(false); if (loginCacheItem == null) { return(StatusCode(400)); } CaptchaImage ci = new CaptchaImage(loginCacheItem.CaptchaText, 240, 60, "Century Schoolbook"); try { // Write the image to the response stream in JPEG format. using (MemoryStream ms = new MemoryStream()) { ci.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return(File(ms.ToArray(), "image/png")); } } catch (Exception err) { if (!err.Message.Contains("Specified method is not supported.")) { throw; } } finally { ci.Dispose(); } return(null); }
protected void Page_Load(object sender, EventArgs e) { string captcha = QueryHelper.GetString("captcha", ""); int width = QueryHelper.GetInteger("width", 80); if (width > MAXSIDESIZE) { width = MAXSIDESIZE; } int height = QueryHelper.GetInteger("height", 20); if (height > MAXSIDESIZE) { height = MAXSIDESIZE; } if (WindowHelper.GetItem("CaptchaImageText" + captcha) != null) { bool useWarp = QueryHelper.GetBoolean("useWarp", true); // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(WindowHelper.GetItem("CaptchaImageText" + captcha).ToString(), width, height, null, useWarp); // Change the response headers to output a JPEG image. Response.Clear(); Response.ContentType = "image/jpeg"; Response.Cache.SetCacheability(HttpCacheability.NoCache); // Write the image to the response stream in JPEG format. ci.Image.Save(Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); RequestHelper.EndResponse(); } }
protected void Page_Load(object sender, EventArgs e) { string color = "000"; string moduleID = ""; if (Request.QueryString.AllKeys.Contains("moduleid")) { moduleID = Request.QueryString["moduleid"]; } if (Request.QueryString.AllKeys.Contains("color")) { color = Request.QueryString["color"]; } string availableCharters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0987654321"; int captchaLenght = 6; string captcha = ""; Random rand = new Random(); for (int i = 1; i <= captchaLenght; i++) { captcha += availableCharters[rand.Next(0, availableCharters.Length)]; } CaptchaImage captchaImage = new CaptchaImage(captcha, 300, 75, color); Response.Clear(); Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. captchaImage.Image.Save(Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. captchaImage.Dispose(); Session["captcha_code_" + moduleID] = captcha; }
public ActionResult Captcha() { var ci = new CaptchaImage(UserSettingsService.CaptchaText, 200, 50); var image = new MemoryStream(); ci.Image.Save(image, ImageFormat.Png); ci.Dispose(); image.Seek(0, SeekOrigin.Begin); return(File(image, @"image/png")); }
public ActionResult Captcha() { Session["Captcha"] = CaptchaImage.RandomString(8); var ci = new CaptchaImage(Session["Captcha"].ToString(), 200, 50, "Helvetica"); Response.Clear(); Response.ContentType = "image/jpeg"; ci.Image.Save(Response.OutputStream, ImageFormat.Jpeg); ci.Dispose(); return(null); }
public ActionResult Captcha() { //храним ключ в сессии клиента. Оттуда его достанем при проверки перед добавлением пользователя в БД Session[CaptchaImage.CaptchaValueKey] = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(); var captchaImage = new CaptchaImage(Session[CaptchaImage.CaptchaValueKey].ToString(), 211, 50, "Arial"); this.Response.Clear(); this.Response.ContentType = "image/jpeg"; captchaImage.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); captchaImage.Dispose(); return(null);//потому что саму капчу записали в выходной поток респонза }
public ActionResult Captcha() { Session[CaptchaImage.CaptchaValueKey] = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(); var ci = new CaptchaImage(Session[CaptchaImage.CaptchaValueKey].ToString(), 211, 50, "Arial"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); return(null); }
protected void Page_Load(object sender, System.EventArgs e) { // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(Session["SecurityCode"].ToString(), 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. Response.Clear(); Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
public ActionResult Captcha() { Session[CaptchaImage.CaptchaValueKey] = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(); var ci = new CaptchaImage(Session[CaptchaImage.CaptchaValueKey].ToString(), 211, 50, "Arial"); this.Response.Clear(); this.Response.ContentType = "image/jpeg"; ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); ci.Dispose(); return(null); }
public ActionResult Captcha() { string code = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(); Session["capcha"] = code; CaptchaImage captcha = new CaptchaImage(code, 110, 50); this.Response.Clear(); this.Response.ContentType = "image/jpeg"; captcha.Image.Save(this.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); captcha.Dispose(); return(null); }
private void Page_Load(object sender, System.EventArgs e) { // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 100, 28, "Lê Bùi Sùng"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
protected void Page_Load(object sender, EventArgs e) { // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 150, 30, "Times New Roman"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
public ActionResult Captcha()//Создает капчу, для проверки на робота { string code = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(); Session["code"] = code; //формируем код и запоминаем его в сессии CaptchaImage captcha = new CaptchaImage(code, 110, 50); //создаем капчу с заданными размерами Response.Clear(); Response.ContentType = "image/jpeg"; captcha.Image.Save(Response.OutputStream, ImageFormat.Jpeg);//сохраняем картинку в формате jpeg captcha.Dispose(); return(null); }
private void Page_Load(object sender, System.EventArgs e) { // Create a CAPTCHA image using the text stored in the Session object. //CaptchaImage ci = new CaptchaImage(Convert.ToString(Session["CaptchaImageText"]), 150, 30, "Verdana"); CaptchaImage ci = new CaptchaImage(Convert.ToString(Session["CaptchaImageText"]), 120, 26, "Verdana"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
public ActionResult Captcha() { int v1 = new Random().Next(50, 99); int v2 = new Random().Next(10, 50); string code = v1.ToString() + "-" + v2.ToString() + "=?"; Session["code"] = code; CaptchaImage captcha = new CaptchaImage(code, 300, 75); this.Response.Clear(); this.Response.ContentType = "image/jpeg"; captcha.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); captcha.Dispose(); return(null); }
//В сессии создаем случайное число от 1111 до 9999. //Создаем в ci объект CatchaImage //Очищаем поток вывода //Задаем header для mime-типа этого http-ответа будет "image/jpeg" т.е. картинка формата jpeg. //Сохраняем bitmap в выходной поток с форматом ImageFormat.Jpeg //Освобождаем ресурсы Bitmap //Возвращаем null, так как основная информация уже передана в поток вывод public ActionResult Captcha() { Session[CaptchaImage.CaptchaValueKey] = new Random(DateTime.Now.Millisecond).Next(1111, 9999).ToString(CultureInfo.InvariantCulture); var ci = new CaptchaImage(Session[CaptchaImage.CaptchaValueKey].ToString(), 211, 50, "Helvetica"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); return null; }
private void Page_Load(object sender, System.EventArgs e) { general = General.Instance; // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(HttpContext.Current.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook"); // CaptchaImage ci = new CaptchaImage(general.CaptchaImageText, 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. Response.Clear(); Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
public void ProcessRequest(HttpContext context) { HttpApplication App = context.ApplicationInstance; HttpContext.Current.Session["CaptchaImageText"] = GenerateRandomCode(); CaptchaImage ci = new CaptchaImage(HttpContext.Current.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. App.Context.Response.Clear(); App.Context.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(App.Context.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); App.Response.StatusCode = 200; context.ApplicationInstance.CompleteRequest(); }
private void Page_Load(object sender, System.EventArgs e) { log.Debug("Entered Page_Load - getcaptchaimage"); log.Debug("Value of captcha session: " + this.Session["CaptchaImageText"] != null ? this.Session["CaptchaImageText"].ToString() : string.Empty); // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); log.Debug("Exiting Page_Load - getcaptchaimage"); }
public void ProcessRequest(HttpContext context) { HttpApplication App = context.ApplicationInstance; HttpContext.Current.Session["CaptchaImageText"] = GenerateRandomCode(); CaptchaImage ci = new CaptchaImage(HttpContext.Current.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. App.Context.Response.Clear(); App.Context.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(App.Context.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); App.Response.StatusCode = 200; context.ApplicationInstance.CompleteRequest(); }
protected void Page_Load(object sender, EventArgs e) { string captcha = QueryHelper.GetString("captcha", ""); int width = QueryHelper.GetInteger("width", 80); if (width > MAXSIDESIZE) { width = MAXSIDESIZE; } int height = QueryHelper.GetInteger("height", 20); if (height > MAXSIDESIZE) { height = MAXSIDESIZE; } if (WindowHelper.GetItem("CaptchaImageText" + captcha) != null) { bool useWarp = QueryHelper.GetBoolean("useWarp", true); // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(WindowHelper.GetItem("CaptchaImageText" + captcha).ToString(), width, height, null, useWarp); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; this.Response.Cache.SetCacheability(HttpCacheability.NoCache); // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); RequestHelper.EndResponse(); } }
protected void Page_Load(object sender, EventArgs e) { string captchaImageText = Convert.ToString(Session["CaptchaImageText"]); if (!this.IsPostBack || string.IsNullOrEmpty(captchaImageText)) { this.Session["CaptchaImageText"] = GenerateRandomCode(); } // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage( this.Session["CaptchaImageText"].ToString(), 225, 40); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.BufferOutput = false; // Get text string s = "No Text"; if (context.Request.QueryString["c"] != null && context.Request.QueryString["c"] != "") { string enc = context.Request.QueryString["c"].ToString(); // space was replaced with + to prevent error enc = enc.Replace(" ", "+"); try { s = Encryptor.Decrypt(enc, "srgerg$%^bg", Convert.FromBase64String("srfjuoxp")); } catch { } } // Get dimensions int w = 120; int h = 50; // Width if (context.Request.QueryString["w"] != null && context.Request.QueryString["w"] != "") { try { w = Convert.ToInt32(context.Request.QueryString["w"]); } catch { } } // Height if (context.Request.QueryString["h"] != null && context.Request.QueryString["h"] != "") { try { h = Convert.ToInt32(context.Request.QueryString["h"]); } catch { } } // Color Color Bc = Color.White; if (context.Request.QueryString["bc"] != null && context.Request.QueryString["bc"] != "") { try { string bc = context.Request.QueryString["bc"].ToString().Insert(0, "#"); Bc = ColorTranslator.FromHtml(bc); } catch { } } // Generate image CaptchaImage ci = new CaptchaImage(s, Bc, w, h); // Return ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg); // Dispose ci.Dispose(); }
protected void btn_Validate(object sender, EventArgs e) { if (CaptchaCode == txt_ccode.Text) { if (txtImePrezime.Text != "" && txtUlica.Text != "" && txtBroj.Text != "" && txtTelefon.Text != "") { try { odrediBroj(); PokupiPodatkeDokument(); for (brojac = 0; brojac < GridView1.Rows.Count; brojac++) { PokupiStavke(); } ShoppingCart cart = ShoppingCart.GetShoppingCart(); cart.ClearItems(); Response.Redirect("Odjava.aspx?value=" + brojNarudzbe + ""); Alert.Show("Vaša narudžba je zaprimljena! \r\n Uskoro će vas kontaktirati operater radi potvrde narudžbe. \r\n Kontrolni broj Vaše narudžbe je " + brojNarudzbe + " \r\n Hvala na Vašoj kupnji."); } catch (Exception ex) { Alert.Show(ex.Message); } } else { Alert.Show("Morate popuniti sva polja sa oznakom *"); } } else { ClientScript.RegisterClientScriptBlock(typeof(Page), "ValidateMsg", "<script>alert('Upisali ste netočne znakove!');</script>"); CaptchaImage cImage = new CaptchaImage(CaptchaImage.generateRandomCode(), 160, 50); cImage.Image.Save(Server.MapPath("~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"), ImageFormat.Jpeg); CaptachaImage.ImageUrl = "~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"; cImage.Dispose(); txt_ccode.Text = ""; txt_ccode.Focus(); } }
protected void Button1_Click(object sender, EventArgs e) { if (CaptchaCode == txt_ccode.Text) { SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress(txtKontakt.Text, txtImePrezime.Text); smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "sokac237"); smtpClient.Port = 587; smtpClient.Host = "smtp.gmail.com"; smtpClient.EnableSsl = true; // You can specify the host name or ipaddress of your server // Default in IIS will be localhost //From address will be given as a MailAddress Object message.From = fromAddress; // To address collection of MailAddress message.To.Add("*****@*****.**"); message.Subject = txtNaslov.Text; //Body can be Html or text format //Specify true if it is html message message.IsBodyHtml = false; // Message body content message.Body = txtTekst.Text + Environment.NewLine + "Kontakt: " + txtKontakt.Text; // Send SMTP mail smtpClient.Send(message); lblStatus.Text = "Poruka je uspješno poslana!"; if (lblStatus.Text == "Poruka je uspješno poslana!") { txtImePrezime.Text = ""; txt_ccode.Text = ""; txtKontakt.Text = ""; txtNaslov.Text = ""; txtTekst.Text = ""; txtImePrezime.Focus(); } } catch (Exception) { lblStatus.Text = "Dogodila se greška. Poruka nije poslan.<br>Neispravna forma e-mail adrese!"; } } else { ClientScript.RegisterClientScriptBlock(typeof(Page), "ValidateMsg", "<script>alert('Upisali ste netočne znakove!');</script>"); CaptchaImage cImage = new CaptchaImage(CaptchaImage.generateRandomCode(), 160, 50); cImage.Image.Save(Server.MapPath("~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"), ImageFormat.Jpeg); CaptachaImage.ImageUrl = "~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"; cImage.Dispose(); txt_ccode.Text = ""; txt_ccode.Focus(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindData(); CaptchaImage cImage = new CaptchaImage(CaptchaImage.generateRandomCode(), 160, 50); cImage.Image.Save(Server.MapPath("~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"), ImageFormat.Jpeg); CaptachaImage.ImageUrl = "~\\CaptchaImages\\" + Convert.ToString(Session["CaptchaCode"]) + ".jpg"; cImage.Dispose(); } CaptchaCode = Convert.ToString(Session["CaptchaCode"]); }