/// <summary>
 /// The default captcha image provider
 /// </summary>
 public CaptchaImageProvider(
     IRandomNumberProvider randomNumberProvider,
     IOptions <DNTCaptchaOptions> options)
 {
     _randomNumberProvider = randomNumberProvider ?? throw new ArgumentNullException(nameof(randomNumberProvider));
     _options = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;
 }
        private static void configOptions(IServiceCollection services, Action <DNTCaptchaOptions> options)
        {
            var captchaOptions = new DNTCaptchaOptions();

            options?.Invoke(captchaOptions);
            setCaptchaStorageProvider(services, captchaOptions);
            setSerializationProvider(services, captchaOptions);
        }
Beispiel #3
0
        /// <summary>
        /// display a numeric value using the equivalent text
        /// </summary>
        public ShowDigitsProvider(IOptions <DNTCaptchaOptions> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _captchaOptions = options.Value;
        }
        /// <summary>
        /// Represents the storage to save the captcha tokens.
        /// </summary>
        public CookieCaptchaStorageProvider(
            ICaptchaCryptoProvider captchaProtectionProvider,
            ILogger <CookieCaptchaStorageProvider> logger,
            IOptions <DNTCaptchaOptions> options)
        {
            _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
            _options = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;

            _logger.LogDebug("Using the CookieCaptchaStorageProvider.");
        }
Beispiel #5
0
 private static void setCaptchaStorageProvider(IServiceCollection services, DNTCaptchaOptions captchaOptions)
 {
     if (captchaOptions.CaptchaStorageProvider == null)
     {
         services.TryAddSingleton <ICaptchaStorageProvider, CookieCaptchaStorageProvider>();
     }
     else
     {
         services.TryAddSingleton(typeof(ICaptchaStorageProvider), captchaOptions.CaptchaStorageProvider);
     }
 }
Beispiel #6
0
 private static void setSerializationProvider(IServiceCollection services, DNTCaptchaOptions captchaOptions)
 {
     if (captchaOptions.CaptchaSerializationProvider == null)
     {
         services.TryAddSingleton <ISerializationProvider, InMemorySerializationProvider>();
     }
     else
     {
         services.TryAddSingleton(typeof(ISerializationProvider), captchaOptions.CaptchaSerializationProvider);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Represents the storage to save the captcha tokens.
        /// </summary>
        public DistributedCacheCaptchaStorageProvider(
            ICaptchaCryptoProvider captchaProtectionProvider,
            IDistributedCache distributedCache,
            ILogger <DistributedCacheCaptchaStorageProvider> logger,
            IOptions <DNTCaptchaOptions> options)
        {
            _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _distributedCache = distributedCache ?? throw new ArgumentNullException(nameof(distributedCache));
            _options          = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;

            _logger.LogDebug("Using the DistributedCacheCaptchaStorageProvider.");
        }
Beispiel #8
0
        private static void configOptions(IServiceCollection services, Action <DNTCaptchaOptions> options)
        {
            var captchaOptions = new DNTCaptchaOptions();

            options?.Invoke(captchaOptions);

            if (captchaOptions.CaptchaStorageProvider == null)
            {
                services.TryAddSingleton <ICaptchaStorageProvider, CookieCaptchaStorageProvider>();
            }
            else
            {
                services.TryAddSingleton(typeof(ICaptchaStorageProvider), captchaOptions.CaptchaStorageProvider);
            }
        }
Beispiel #9
0
 /// <summary>
 /// Serialization Provider
 /// </summary>
 public InMemorySerializationProvider(
     IMemoryCache memoryCache,
     ICaptchaCryptoProvider captchaProtectionProvider,
     ILogger <InMemorySerializationProvider> logger,
     IOptions <DNTCaptchaOptions> options)
 {
     _memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     _options = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;
     _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
     logger.LogDebug("Using the InMemorySerializationProvider.");
 }
Beispiel #10
0
 /// <summary>
 /// Validates the input number.
 /// </summary>
 public DNTCaptchaValidatorService(
     IHttpContextAccessor contextAccessor,
     ILogger <DNTCaptchaValidatorService> logger,
     ICaptchaCryptoProvider captchaProtectionProvider,
     ICaptchaStorageProvider captchaStorageProvider,
     Func <DisplayMode, ICaptchaTextProvider> captchaTextProvider,
     IOptions <DNTCaptchaOptions> options
     )
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
     _captchaStorageProvider    = captchaStorageProvider ?? throw new ArgumentNullException(nameof(captchaStorageProvider));
     _captchaTextProvider       = captchaTextProvider ?? throw new ArgumentNullException(nameof(captchaTextProvider));
     _contextAccessor           = contextAccessor ?? throw new ArgumentNullException(nameof(contextAccessor));
     _captchaOptions            = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;
 }
 /// <summary>
 /// DNTCaptcha TagHelper
 /// </summary>
 public DNTCaptchaTagHelper(
     ICaptchaCryptoProvider captchaProtectionProvider,
     IRandomNumberProvider randomNumberProvider,
     Func <DisplayMode, ICaptchaTextProvider> captchaTextProvider,
     ICaptchaStorageProvider captchaStorageProvider,
     IAntiforgery antiforgery,
     ISerializationProvider serializationProvider,
     IOptions <DNTCaptchaOptions> options
     )
 {
     _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
     _randomNumberProvider      = randomNumberProvider ?? throw new ArgumentNullException(nameof(randomNumberProvider));
     _captchaTextProvider       = captchaTextProvider ?? throw new ArgumentNullException(nameof(captchaTextProvider));
     _captchaStorageProvider    = captchaStorageProvider ?? throw new ArgumentNullException(nameof(captchaStorageProvider));
     _antiforgery           = antiforgery ?? throw new ArgumentNullException(nameof(antiforgery));
     _serializationProvider = serializationProvider ?? throw new ArgumentNullException(nameof(serializationProvider));
     _captchaOptions        = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;
 }
 /// <summary>
 /// DNTCaptcha Api
 /// </summary>
 public DNTCaptchaApiProvider(
     ICaptchaCryptoProvider captchaProtectionProvider,
     IRandomNumberProvider randomNumberProvider,
     Func <DisplayMode, ICaptchaTextProvider> captchaTextProvider,
     ICaptchaStorageProvider captchaStorageProvider,
     ISerializationProvider serializationProvider,
     IHttpContextAccessor httpContextAccessor,
     IUrlHelper urlHelper,
     IOptions <DNTCaptchaOptions> options)
 {
     _captchaProtectionProvider = captchaProtectionProvider ?? throw new ArgumentNullException(nameof(captchaProtectionProvider));
     _randomNumberProvider      = randomNumberProvider ?? throw new ArgumentNullException(nameof(randomNumberProvider));
     _captchaTextProvider       = captchaTextProvider ?? throw new ArgumentNullException(nameof(captchaTextProvider));
     _captchaStorageProvider    = captchaStorageProvider ?? throw new ArgumentNullException(nameof(captchaStorageProvider));
     _serializationProvider     = serializationProvider ?? throw new ArgumentNullException(nameof(serializationProvider));
     _httpContextAccessor       = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     _urlHelper      = urlHelper ?? throw new ArgumentNullException(nameof(urlHelper));
     _captchaOptions = options == null ? throw new ArgumentNullException(nameof(options)) : options.Value;
 }