public void Init() { var builder = new ConfigurationBuilder() .SetBasePath("") .AddJsonFile("appsettings.json"); builder.AddEnvironmentVariables(); Configuration = builder.Build(); sqlConnectionString = Configuration["Data:ConnectionString"]; string cloudStorageConnectionString = Configuration["Data:StorageConnectionString"]; _options = new BlockingAlgorithmOptions(); DbContextOptionsBuilder <DbUserAccountContext> dbOptionsBuilder = new DbContextOptionsBuilder <DbUserAccountContext>(); dbOptionsBuilder.UseSqlServer(sqlConnectionString); dbOptions = dbOptionsBuilder.Options; _CloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString); userAccountControllerFactory = new DbUserAccountControllerFactory(_CloudStorageAccount, dbOptions); userAccountController = userAccountControllerFactory.CreateDbUserAccountController(); RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:35358") }; MaxWeightHashing <RemoteHost> hosts = new MaxWeightHashing <RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]); LoginAttemptClient <DbUserAccount> loginAttemptClient = new LoginAttemptClient <DbUserAccount>(hosts, localHost); _UserAccountRepositoryFactory = new DbUserAccountRepositoryFactory(dbOptions); BinomialLadderFilter localPasswordBinomialLadderFilter = new BinomialLadderFilter( _options.NumberOfBitsInBinomialLadderFilter_N, _options.HeightOfBinomialLadder_H); _loginAttemptController = new LoginAttemptController <DbUserAccount>( userAccountControllerFactory, _UserAccountRepositoryFactory, localPasswordBinomialLadderFilter, new MemoryUsageLimiter(), _options); //services.AddEntityFramework() // .AddSqlServer() // .AddDbContext<DbUserAccountContext>(opt => opt.UseSqlServer(sqlConnectionString)); //DbUserAccountContext context = new DbUserAccountContext(); //var db = new DbContextOptionsBuilder(); //db.UseInMemoryDatabase(); //_context = new MyContext(db.Options); }
public void Init() { var builder = new ConfigurationBuilder() .SetBasePath("") .AddJsonFile("appsettings.json"); builder.AddEnvironmentVariables(); Configuration = builder.Build(); sqlConnectionString = Configuration["Data:ConnectionString"]; string cloudStorageConnectionString = Configuration["Data:StorageConnectionString"]; _options = new BlockingAlgorithmOptions(); DbContextOptionsBuilder<DbUserAccountContext> dbOptionsBuilder = new DbContextOptionsBuilder<DbUserAccountContext>(); dbOptionsBuilder.UseSqlServer(sqlConnectionString); dbOptions = dbOptionsBuilder.Options; _CloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString); userAccountControllerFactory = new DbUserAccountControllerFactory(_CloudStorageAccount, dbOptions); userAccountController = userAccountControllerFactory.CreateDbUserAccountController(); RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:35358") }; MaxWeightHashing<RemoteHost> hosts = new MaxWeightHashing<RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]); LoginAttemptClient<DbUserAccount> loginAttemptClient = new LoginAttemptClient<DbUserAccount>(hosts, localHost); _UserAccountRepositoryFactory = new DbUserAccountRepositoryFactory(dbOptions); BinomialLadderFilter localPasswordBinomialLadderFilter = new BinomialLadderFilter( _options.NumberOfBitsInBinomialLadderFilter_N, _options.HeightOfBinomialLadder_H); _loginAttemptController = new LoginAttemptController<DbUserAccount>( userAccountControllerFactory, _UserAccountRepositoryFactory, localPasswordBinomialLadderFilter, new MemoryUsageLimiter(), _options); //services.AddEntityFramework() // .AddSqlServer() // .AddDbContext<DbUserAccountContext>(opt => opt.UseSqlServer(sqlConnectionString)); //DbUserAccountContext context = new DbUserAccountContext(); //var db = new DbContextOptionsBuilder(); //db.UseInMemoryDatabase(); //_context = new MyContext(db.Options); }
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; }