protected override void Post(HttpContext context) { var user = Utility.Deserialize <UserLogin>(GetReceivedContent(context)); IValidateLogin validateLogin = new LoginValidator(); IValidateCaptcha validateCaptcha = new CaptchaValidator(); if (validateLogin.IsValidLogin(user) == true && validateCaptcha.IsValid(user.Captcha, context) == true) { // 更新UpdateTime var currentUser = LoginValidator.Users.Where(u => u.UserName == user.UserName).FirstOrDefault(); currentUser.LoginTime = DateTime.Now; DB.UpdateUser(currentUser); // 清空Session:Captcha context.Session.Remove(SessionKeys.Captcha); // 增加Session:LoginUser context.Session.Add(SessionKeys.LoginUser, user); // 返回 OK(Response, new JsonResponse() { code = RespCode.redirect, message = "ok", respObj = "/views/workpanel.html" }); } else { OK(Response, new JsonResponse() { code = RespCode.notok, message = "failed" }); } }
protected void Page_Load(object sender, EventArgs e) { RequiredFieldValidator3.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("LegendLogin"))); RequiredFieldValidator4.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("LegendPassword"))); MasterTitle = Page.Title; divLoginFooterHint.Visible = BXUserManager.Provider.EnablePasswordReset; _captchaValidator = new CaptchaValidator(hfCaptchaGuid, tbxCaptcha, errorMessage); _captchaValidator.ID = "cvCaptcha"; captchaPlaceHolder.Controls.Add(_captchaValidator); _captchaValidator.ValidationGroup = "vgLoginForm"; #region old //if (BXUserManager.Provider.RequiresQuestionAndAnswer) // divLoginFooterHint.InnerHtml = string.Format( // "<p><b>{0}</b></p><p>{1}</p>", // GetMessage("DoYouForgetPassword"), // string.Format(GetMessage("FormatGo2PasswordRecoveryForm"), "<a href=\"PasswordRecovery.aspx\">", "</a>") // ); //if (BXUserManager.Provider.RequiresCheckWord) // divLoginFooterHint.InnerHtml = string.Format( // "<p><b>{0}</b></p><p>{1}</p><p>{2}</p>", // GetMessage("DoYouForgetPassword"), // string.Format(GetMessage("FormatGo2PasswordRecoveryForm"), "<a href=\"PasswordRecoveryAlt.aspx\">", "</a>"), // string.Format(GetMessage("FormatGo2PasswordChangeForm"), "<a href=\"PasswordRecoveryAlt1.aspx\">", "</a>") // ); #endregion }
public StatusModel(Database database, HtmlSanitizer sanitizer, QuestionHandler questionHandler, IConfiguration configuration, CaptchaValidator validator, MarkdownPipeline markdown) { this.database = database; this.sanitizer = sanitizer; this.questionHandler = questionHandler; this.validator = validator; this.markdown = markdown; SiteKey = configuration.GetValue <string>("Captcha:SiteKey"); }
public ActionResult Submit(string url, string title, string category, string description, string tags) { string captchaChallenge = null; string captchaResponse = null; bool captchaEnabled = !CurrentUser.ShouldHideCaptcha(); if (captchaEnabled) { captchaChallenge = HttpContext.Request.Form[CaptchaValidator.ChallengeInputName]; captchaResponse = HttpContext.Request.Form[CaptchaValidator.ResponseInputName]; } JsonViewData viewData = Validate <JsonViewData>( new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaChallenge), "Captcha challenge cannot be blank."), new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaResponse), "Captcha verification words cannot be blank."), new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."), new Validation(() => captchaEnabled && !CaptchaValidator.Validate(CurrentUserIPAddress, captchaChallenge, captchaResponse), "Captcha verification words are incorrect.") ); if (viewData == null) { try { StoryCreateResult result = _storyService.Create( CurrentUser, url.NullSafe(), title.NullSafe(), category.NullSafe(), description.NullSafe(), tags.NullSafe(), CurrentUserIPAddress, HttpContext.Request.UserAgent, ((HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : null), HttpContext.Request.ServerVariables, story => string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })) ); viewData = new JsonCreateViewData { isSuccessful = string.IsNullOrEmpty(result.ErrorMessage), errorMessage = result.ErrorMessage, url = result.DetailUrl }; } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("submitting story") }; } } return(Json(viewData)); }
static void Main(string[] args) { CaptchaValidator cv = new CaptchaValidator(); var cap = cv.Generate(5, System.Drawing.Color.DarkOrange, TimeSpan.FromHours(1)); string b64 = cap.Base64Image; string password = "******"; bool isValid = cap.Validate(password); }
protected void Page_Load(object sender, EventArgs e) { MasterTitle = Page.Title; _captchaValidator = new CaptchaValidator(hfCaptchaGuid, tbxCaptcha, errorMessage); _captchaValidator.ID = "cvCaptcha"; captchaPlaceHolder.Controls.Add(_captchaValidator); _captchaValidator.ValidationGroup = "vgLoginForm"; if (!BXUserManager.Provider.EnablePasswordReset || !BXUserManager.Provider.RequiresCheckWord) errorMessage.AddErrorMessage(GetMessage("Error.PasswordRecoveryByControlStringIsInaccessible")); }
public AskModel(ILogger <AskModel> logger, HomeAssistantService homeAssistant, NotificationBuilder notificationBuilder, HtmlSanitizer sanitizer, IConfiguration configuration, CaptchaValidator validator, MarkdownPipeline markdown, Database database) { _logger = logger; this.homeAssistant = homeAssistant; this.notificationBuilder = notificationBuilder; this.sanitizer = sanitizer; this.configuration = configuration; this.validator = validator; this.markdown = markdown; this.database = database; SiteKey = configuration.GetValue <string>("Captcha:SiteKey"); }
public IHttpActionResult ValidateCaptcha(CaptchaValidator.Captcha captcha) { if (!CaptchaValidator.IsValid(captcha)) { ModelState.AddModelError("Captcha", "Invalid Captcha"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok()); }
protected void Page_Load(object sender, EventArgs e) { RequiredFieldValidator1.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("Legend.Login"))); RequiredFieldValidator2.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("Legend.ControlString"))); RequiredFieldValidator3.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("Legend.NewPassword"))); RequiredFieldValidator4.ErrorMessage = Encode(string.Format(GetMessageRaw("Message.FillField"), GetMessageRaw("Legend.PasswordConfirmation"))); MasterTitle = Page.Title; if (!Page.IsPostBack) if (Page.Request.QueryString["checkword"] != null) tbCheckWord.Text = Page.Request.QueryString["checkword"]; _captchaValidator = new CaptchaValidator(hfCaptchaGuid, tbxCaptcha, errorMessage); _captchaValidator.ID = "cvCaptcha"; captchaPlaceHolder.Controls.Add(_captchaValidator); _captchaValidator.ValidationGroup = "vgLoginForm"; }
protected void Page_Load(object sender, EventArgs e) { MasterTitle = Page.Title; divPasswordRecoveryStep1.Visible = true; divPasswordRecoveryStep2.Visible = false; _captchaValidator = new CaptchaValidator(hfCaptchaGuid, tbxCaptcha, errorMessage); _captchaValidator.ID = "cvCaptcha"; _captchaValidator.ValidationGroup = "vgLoginForm"; captchaPlaceHolder.Controls.Add(_captchaValidator); if (!BXUserManager.Provider.EnablePasswordReset || !BXUserManager.Provider.RequiresQuestionAndAnswer) errorMessage.AddErrorMessage(GetMessage("Error.PasswordRecoveryBySecretQuestionIsInaccessible")); }
public ActionResult Submit(string url, string title, string category, string description, string tags) { string captchaChallenge = null; string captchaResponse = null; bool captchaEnabled = !CurrentUser.ShouldHideCaptcha(); if (captchaEnabled) { captchaChallenge = HttpContext.Request.Form[CaptchaValidator.ChallengeInputName]; captchaResponse = HttpContext.Request.Form[CaptchaValidator.ResponseInputName]; } JsonViewData viewData = Validate <JsonViewData>( new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaChallenge), "Pole Captcha nie mo¿e byæ puste."), new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaResponse), "Pole Captcha nie mo¿e byæ puste."), new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany"), new Validation(() => captchaEnabled && !CaptchaValidator.Validate(CurrentUserIPAddress, captchaChallenge, captchaResponse), "Nieudana weryfikacja Captcha") ); if (viewData == null) { try { using (IUnitOfWork unitOfWork = UnitOfWork.Get()) { StoryCreateResult result = _storyService.Create( CurrentUser, url.NullSafe(), title.NullSafe(), category.NullSafe(), description.NullSafe(), tags.NullSafe(), CurrentUserIPAddress, HttpContext.Request.UserAgent, ((HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : null), HttpContext.Request.ServerVariables, story => string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })) ); viewData = new JsonCreateViewData { isSuccessful = string.IsNullOrEmpty(result.ErrorMessage), errorMessage = result.ErrorMessage, url = result.DetailUrl }; unitOfWork.Commit(); } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("dodania artyku³u") }; } } return(Json(viewData)); }