public LoginAttemptController( IUserAccountControllerFactory <TUserAccount> userAccountControllerFactory, IUserAccountRepositoryFactory <TUserAccount> userAccountRepositoryFactory, IBinomialLadderFilter binomialLadderFilter, MemoryUsageLimiter memoryUsageLimiter, BlockingAlgorithmOptions blockingOptions ) { _options = blockingOptions; _binomialLadderFilter = binomialLadderFilter; _userAccountRepositoryFactory = userAccountRepositoryFactory; _userAccountControllerFactory = userAccountControllerFactory; _recentIncorrectPasswords = new AgingMembershipSketch(blockingOptions.AgingMembershipSketchTables, blockingOptions.AgingMembershipSketchTableSize); _ipHistoryCache = new SelfLoadingCache <IPAddress, IpHistory>(address => new IpHistory(address, _options)); memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage; }
/// <summary> /// Construct the controller. /// </summary> /// <param name="userAccountControllerFactory">A factory for creating IUserAccountController interfaces for managing user account records.</param> /// <param name="userAccountRepositoryFactory">A factory for creating IAccountRepository interfaces for obtaining user account records.</param> /// <param name="binomialLadderFilter">A binomial ladder frequency that the controller should use to track frequently-guessed passwords.</param> /// <param name="memoryUsageLimiter">A memory usage limiter that the controller should register into so that when memory is tight, /// the controller can do its part to free up cached items it may not need anymore.</param> /// <param name="blockingOptions">Configuration options.</param> public LoginAttemptController( IUserAccountControllerFactory <TUserAccount> userAccountControllerFactory, IUserAccountRepositoryFactory <TUserAccount> userAccountRepositoryFactory, IBinomialLadderFilter binomialLadderFilter, MemoryUsageLimiter memoryUsageLimiter, BlockingAlgorithmOptions blockingOptions ) { // Copy parameters into the controller. _options = blockingOptions; _binomialLadderFilter = binomialLadderFilter; _userAccountRepositoryFactory = userAccountRepositoryFactory; _userAccountControllerFactory = userAccountControllerFactory; // Create a membership sketch to track username/password pairs that have failed. _recentIncorrectPasswords = new AgingMembershipSketch(blockingOptions.AgingMembershipSketchTables, blockingOptions.AgingMembershipSketchTableSize); // Create a cache of records storing information about the behavior of IPs that have issued login attempts. _ipHistoryCache = new SelfLoadingCache <IPAddress, IpHistory>(address => new IpHistory(address, _options)); // When memory is low, the memeory usage limiter should call the ReduceMemoryUsage method of this controller. memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage; }