示例#1
0
        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);
        }
        private bool isValidCookie(HttpContext httpContext, string decryptedText, string cookieToken)
        {
            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 result = cookieValue.Equals(decryptedText);

            if (!result)
            {
                _logger.LogInformation($"isValidCookie:: {cookieValue} != {decryptedText}");
            }
            return(result);
        }
示例#3
0
        public bool VerifyCaptcha(string name, string value)
        {
            if (!_captchaOptions.Enable)
            {
                return(true);
            }
            var isValid = false;

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
            {
                //validate request
                var captchaText = _captchaStorageProvider.GetValue(_httpContextAccessor.HttpContext, name);
                if (value.Equals(captchaText, StringComparison.OrdinalIgnoreCase))
                {
                    isValid = true;
                    Remove(name);
                }
            }
            return(isValid);
        }