public CaptchaAPI(CaptchaProvider _provider, string _api) { provider = _provider; api = _api; success_count = 0; fail_count = 0; }
public CaptchaAPI(CaptchaProvider _provider, string _api, int _order) { provider = _provider; api = _api; success_count = 0; fail_count = 0; enabled = false; order = _order; }
/// <summary> /// 显示验证码图片 /// </summary> public void ToImage() { string codes = Utils.GetRandCode(4); this.pg.Session.Add("VerifyCodes", codes); CaptchaInfo captcha = CaptchaProvider.GetInstance().GenerateImage(codes, 200, 40, System.Drawing.Color.WhiteSmoke); this.pg.Response.Clear(); this.pg.Response.ContentType = captcha.ContentType; captcha.Image.Save(this.pg.Response.OutputStream, captcha.ImageFormat); }
protected void btnbtnGui_Click(object sender, EventArgs e) { // Neu tat ca du lieu deu duoc nhap hop le if (Page.IsValid) { CaptchaProvider captchaPro = new CaptchaProvider(); if (captchaPro.IsValidCode(txtInputString.Text)) { lbcapcha.Visible = false; bool rs = false; HoiDap data = new HoiDap(); data.HoTen = txtHoTen.Text; data.Email = txtEmail.Text; data.TieuDe = txtTieuDe.Text; data.NoiDungHoi = txtNoiDung.Text; data.NoiDungDap = ""; data.DiaChi = txtDiaChi.Text; data.NgayGui = DateTime.Now; data.TrangThai = 0; rs = HoiDap.Them(data); if (rs) { succesfull.Visible = true; refesh(); succesfull.Text = "Nội dung liên hệ của bạn đã được gủi đến bệnh viện Nam Bình Thuận. Chúng tôi sẽ trả lời liên hệ của bạn trong thời gian sớm nhất!"; } else { succesfull.Visible = true; succesfull.Text = "Gửi ý kiến thất bại!"; } } else { lbcapcha.Visible = true; succesfull.Visible = false; lbcapcha.Text = "Sai mã xác nhận!"; } } }
protected override void OnInit(EventArgs e) { if (this.Site != null && this.Site.DesignMode) { } else { base.OnInit(e); // an exception always happens here in design mode // this try is just to fix the display in design view in VS try { captchProvider = CaptchaManager.Providers[providerName]; captcha = captchProvider.GetCaptcha(); this.Controls.Add(captcha.GetControl()); } catch { } } }
protected void btnbtnGui_Click(object sender, EventArgs e) { // Neu tat ca du lieu deu duoc nhap hop le if (Page.IsValid) { CaptchaProvider captchaPro = new CaptchaProvider(); if (captchaPro.IsValidCode(txtInputString.Text)) { lbcapcha.Visible = false; bool rs = false; LienHe data = new LienHe(); data.HoTen = txtHoTen.Text; data.Email = txtEmail.Text; data.TieuDe = txtTieuDe.Text; data.NoiDung = txtNoiDung.Text; data.DiaChi = txtDiaChi.Text; data.NgayGui = DateTime.Now; data.TrangThai = 0; data.TheLoai = 1; rs = LienHe.Them(data); if (rs) { succesfull.Visible = true; refesh(); succesfull.Text = "Sent Successfull!"; } else { succesfull.Visible = true; succesfull.Text = "Failed send!"; } } else { lbcapcha.Visible = true; succesfull.Visible = false; lbcapcha.Text = "Incorrect code!"; } } }
public async Task ResetAsync(CommandContext ctx) { using (var db = this.Database.CreateContext()) { var cfg = db.GuildConfig.SingleOrDefault(xc => (ulong)xc.GuildId == ctx.Guild.Id); if (cfg == null) { await ctx.SafeRespondAsync("This guild is not configured."); return; } var captcha = GetUniqueKey(32); await ctx.RespondWithFileAsync( $"{GetUniqueKey(64)}.png", new MemoryStream(CaptchaProvider.DrawCaptcha(captcha, "#99AAB5", "#23272A", 24, "Courier New")), "You are about to reset the configuration for this guild. **This change is irreversible.** " + "Type the characters in the image to continue. You have 45 seconds."); var msg = await this.Interactivity .WaitForMessageAsync(xm => xm.Author.Id == ctx.User.Id && xm.Content.ToUpperInvariant() == captcha, TimeSpan.FromSeconds(45)); if (msg.Result == null) { await ctx.SafeRespondAsync("Operation aborted."); return; } db.GuildConfig.Remove(cfg); await db.SaveChangesAsync(); } await ctx.SafeRespondAsync("Configuration reset."); }
static RequiresCaptchaAttribute() { var captchaConfig = FormBuilderConfiguration.GetSection().Captcha; Provider = (CaptchaProvider)captchaConfig.Providers[captchaConfig.DefaultProvider]; }
protected void Page_Load(object sender, EventArgs e) { if (!ApplicationSettings.PostingEnabled) { Response.StatusCode = 403; this.Response.Write(Language.Lang.postingisdisabled); this.Response.End(); } if (string.IsNullOrEmpty(Request["mode"])) { Response.StatusCode = 403; Response.Write("403"); Response.End(); } using (DbConnection con = DatabaseEngine.GetDBConnection()) { con.Open(); //check bans if (Board.BanHandler.IsIPBanned(Request.UserHostAddress, con)) { Response.Redirect(Paths.WebRoot + "banned.aspx", true); } //bool is_admin = false; //bool is_mod = false; bool all_ok = true; //check flood //check captcha if (!CaptchaProvider.Verifiy(this.Context)) { this.Response.Write(Language.Lang.wrongcaptcha); this.Response.End(); } //check file sizes for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFile file = Request.Files[i]; if (file.ContentLength > ApplicationSettings.MaximumFileSize) { Response.Write(string.Format("The file '{0}' is larger than the allowed limit {1}.", file.FileName, ApplicationSettings.MaximumFileSize)); all_ok = false; break; } } if (all_ok) { switch (Request["mode"]) { case "thread": if (Request.Files.Count == 0 | Request.Files["ufile"].ContentLength == 0) { Response.Write("You need a file to start a thread"); } else { OPData op_data = new DataTypes.OPData() { Comment = Request["comment"], Email = Request["email"], Name = Request["name"], Subject = Request["subject"], Password = Request["password"], HasFile = true, IP = Request.UserHostAddress, UserAgent = Request.UserAgent, Time = DateTime.UtcNow }; int thread_id = -1; try { thread_id = Board.BoardCommon.MakeThread(op_data, Request.Files["ufile"], con); Response.Redirect(Paths.WebRoot + "default.aspx?id=" + thread_id.ToString(), true); } catch (Exception ex) { Response.Write(ex.Message); } } break; case "reply": if (string.IsNullOrEmpty(Request["threadid"])) { Response.Write("Thread id is not specified"); } else { int thread_id = -1; try { thread_id = Convert.ToInt32(Request["threadid"]); if (thread_id <= 0) { Response.Write("Invalid thread id"); Response.End(); } } catch (Exception) { Response.Write("Invalid thread id"); Response.End(); } ThreadInfo t_info = BoardCommon.GetThreadInfo(thread_id, con); if (t_info.isGone) { Response.Write("Thread does not exist."); Response.End(); } if (t_info.isLocked) { Response.Write("Thread is locked."); Response.End(); } if (t_info.isArchived) { Response.Write("Thread is archived."); Response.End(); } if (ApplicationSettings.EnableImpresonationProtection) { //do stuffs } List <HttpPostedFile> proper_files = new List <HttpPostedFile>(); //Discard any empty file field for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFile file = Request.Files[i]; if (file.ContentLength > 0) { proper_files.Add(file); } } bool file_in_each_post = (Request["finp"] == "yes"); bool count_files = (Request["countf"] == "yes"); bool sage = (Request["email"] == "sage"); OPData op_data = new OPData() { Comment = Request["comment"], Email = sage ? "" : Request["email"], Name = Request["name"], Subject = Request["subject"], Password = Request["password"], IP = Request.UserHostAddress, UserAgent = Request.UserAgent, Time = DateTime.UtcNow }; int reply_id = -1; try { reply_id = BoardCommon.ReplyTo(op_data, thread_id, proper_files.ToArray(), file_in_each_post, count_files, con); if (reply_id > 0) { //Update thread body if (ApplicationSettings.CacheIndexView) { IndexView.UpdateThreadIndex(thread_id, con); } if (ApplicationSettings.CacheThreadView) { ThreadView.UpdateThreadBody(thread_id, con); } if (!sage) { BoardCommon.BumpThread(thread_id, con); } Response.Redirect(Paths.WebRoot + string.Format("default.aspx?id={0}#p{1}", thread_id, reply_id)); } } catch (Exception ex) { Response.Write(ex.Message); } } break; default: Response.Write(string.Format("Invalid posting mode '{0}'", Request["mode"])); break; } //mode switch block } // if all ok block } // database connection using block } //page load void
protected void Page_Load(object sender, EventArgs e) { bool do_action = (!string.IsNullOrEmpty(Request["id"]) & Request["mode"] == "deletefile"); if (do_action) { int id = -1; Int32.TryParse(Request["id"], out id); if (id <= 0) { Response.Write("Invalid post id."); Response.End(); } using (DbConnection dc = Database.DatabaseEngine.GetDBConnection()) { dc.Open(); WPost post = Board.BoardCommon.GetPostData(id, dc); if (post == null) { Response.Write("Post does not exist"); Response.End(); } else { //first check captcha, then check password, and finally delete files if (CaptchaProvider.Verifiy(this.Context)) { if (Request["pwd"] == post.Password) //pwd is the user input password { //We should gather a list of files hashes, and delete them List <string> file_hashes = new List <string>(); foreach (string qs in this.Request.Form) { if (qs.StartsWith("file")) { file_hashes.Add(qs.Remove(0, 4)); } } if (file_hashes.Count > 0) { BoardCommon.DeleteFileFromDatabase(id, file_hashes.ToArray(), dc); if (Settings.ApplicationSettings.AutoDeleteFiles) { foreach (WPostFile file in post.Files) { if (file_hashes.Contains(file.Hash)) { //remove the files physically from the disk System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalFilesStorageFolder, file.ChanbName + "." + file.Extension)); //delete thumbs as well System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalThumbStorageFolder, file.ChanbName + ".jpg")); System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalThumbStorageFolder, file.ChanbName + ".png")); } } } //update thread page and index. IndexView.UpdateThreadIndex(id, dc); ThreadView.UpdateThreadBody(id, dc); Response.Write(file_hashes.Count + " files deleted successfully"); } else { //No file was selected. Redirect to the delete file page, with 'no file selected' notice. Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?ns=1&id=" + id.ToString(), true); //ns == no file seleted } } else { //Bad password. Redirect to the delete file page, with 'bad password' notice. Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?bp=1&id=" + id.ToString(), true); //bp == bad password } } else { //invalid captcha. Redirect to the delete file page, with 'bad captcha' notice Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?wc=1&id=" + id.ToString(), true); //wc == wrong captcha } } } } else { int id = -1; Int32.TryParse(Request["id"], out id); if (id <= 0) { Response.Write("Invalid post id."); Response.End(); } using (DbConnection dc = Database.DatabaseEngine.GetDBConnection()) { dc.Open(); WPost post = Board.BoardCommon.GetPostData(id, dc); if (post == null) { Response.Write("Post does not exist"); Response.End(); } else { if (post.FileCount == 0) { Response.Write("Post has no files"); Response.End(); } else if (post.FileCount == 1) { if (string.IsNullOrEmpty(post.Comment) & post.Type == Enums.PostType.Reply) { Response.Write("Cannot delete this post because it has no comment and only a single file. \n Delete the post instead."); Response.End(); } else { //show delete file page Response.Write(generate_page(post)); } } else { Response.Write(generate_page(post)); } } } } }