private bool isValidCookie(HttpContext httpContext, string decryptedText, string?cookieToken) { if (string.IsNullOrEmpty(cookieToken)) { _logger.LogDebug("CaptchaHiddenTokenName is empty."); return(false); } cookieToken = _captchaProtectionProvider.Decrypt(cookieToken); if (string.IsNullOrEmpty(cookieToken)) { _logger.LogDebug("CaptchaHiddenTokenName is invalid."); return(false); } var cookieValue = _captchaStorageProvider.GetValue(httpContext, cookieToken); if (string.IsNullOrWhiteSpace(cookieValue)) { _logger.LogDebug("isValidCookie:: cookieValue IsNullOrWhiteSpace."); return(false); } var areEqual = cookieValue.Equals(decryptedText, StringComparison.Ordinal); if (!areEqual) { _logger.LogDebug($"isValidCookie:: {cookieValue} != {decryptedText}"); } _captchaStorageProvider.Remove(httpContext, cookieToken); return(areEqual); }
public IActionResult Refresh(string rndDate, DNTCaptchaTagHelperHtmlAttributes model) { _captchaStorageProvider.Remove(HttpContext, model.CaptchaToken); var tagHelper = HttpContext.RequestServices.GetRequiredService <DNTCaptchaTagHelper>(); tagHelper.BackColor = model.BackColor; tagHelper.FontName = model.FontName; tagHelper.FontSize = model.FontSize; tagHelper.ForeColor = model.ForeColor; tagHelper.Language = model.Language; tagHelper.Max = model.Max; tagHelper.Min = model.Min; tagHelper.Placeholder = model.Placeholder; tagHelper.TextBoxClass = model.TextBoxClass; tagHelper.TextBoxTemplate = model.TextBoxTemplate; tagHelper.ValidationErrorMessage = model.ValidationErrorMessage; tagHelper.ValidationMessageClass = model.ValidationMessageClass; tagHelper.RefreshButtonClass = model.RefreshButtonClass; var tagHelperContext = new TagHelperContext( allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: Guid.NewGuid().ToString("N")); var tagHelperOutput = new TagHelperOutput( tagName: "div", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent(string.Empty); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); tagHelper.ViewContext = ViewContext ?? new ViewContext( new ActionContext(this.HttpContext, HttpContext.GetRouteData(), ControllerContext.ActionDescriptor), new FakeView(), new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { Model = null }, new TempDataDictionary(this.HttpContext, _tempDataProvider), TextWriter.Null, new HtmlHelperOptions()); tagHelper.Process(tagHelperContext, tagHelperOutput); var attrs = new StringBuilder(); foreach (var attr in tagHelperOutput.Attributes) { attrs.Append($" {attr.Name}='{attr.Value}'"); } var content = $"<div {attrs}>{tagHelperOutput.Content.GetContent()}</div>"; return(Content(content)); }
private bool isValidCookie(HttpContext httpContext, string decryptedText, string cookieToken, bool deleteCookieAfterValidation) { if (string.IsNullOrEmpty(cookieToken)) { _logger.LogInformation("CaptchaHiddenTokenName is empty."); return(false); } cookieToken = _captchaProtectionProvider.Decrypt(cookieToken); if (string.IsNullOrEmpty(cookieToken)) { _logger.LogInformation("CaptchaHiddenTokenName is invalid."); return(false); } var cookieValue = _captchaStorageProvider.GetValue(httpContext, cookieToken); if (string.IsNullOrWhiteSpace(cookieValue)) { _logger.LogInformation("isValidCookie:: cookieValue IsNullOrWhiteSpace."); return(false); } var areEqual = cookieValue.Equals(decryptedText); if (!areEqual) { _logger.LogInformation($"isValidCookie:: {cookieValue} != {decryptedText}"); } if (areEqual && deleteCookieAfterValidation) { _captchaStorageProvider.Remove(httpContext, cookieToken); } return(areEqual); }
public void Remove(string name) { _captchaStorageProvider.Remove(_httpContextAccessor.HttpContext, name); }
private void invalidateToken(DNTCaptchaTagHelperHtmlAttributes model) { _captchaStorageProvider.Remove(HttpContext, model.CaptchaToken); }