private static void AddPasswordHistoryEntry(Guid accountID, string password)
 {
     using (var db = new CustomDatabase())
     {
         var pw = new PasswordHistory
         {
             UserID       = accountID,
             DateChanged  = DateTime.UtcNow,
             PasswordHash = new DefaultCrypto().HashPassword(password, 1000)
         };
         db.PasswordHistory.Add(pw);
         db.SaveChanges();
     }
 }
 public void Handle(PasswordChangedEvent evt)
 {
     using (var db = new CustomDatabase())
     {
         var pw = new PasswordHistory
         {
             UserID       = evt.Account.ID,
             DateChanged  = DateTime.UtcNow,
             PasswordHash = evt.Account.HashedPassword
         };
         db.PasswordHistory.Add(pw);
         db.SaveChanges();
     }
 }
 public void Handle(FailedLoginEvent <CustomUserAccount> evt)
 {
     using (var db = new CustomDatabase())
     {
         var audit = new AuthenticationAudit
         {
             Date     = DateTime.UtcNow,
             Activity = "Login Failure",
             Detail   = evt.GetType().Name + ", Failed Login Count: " + evt.Account.FailedLoginCount,
             ClientIP = HttpContext.Current.Request.UserHostAddress,
         };
         db.Audits.Add(audit);
         db.SaveChanges();
     }
 }
 public void Handle(SuccessfulLoginEvent <CustomUserAccount> evt)
 {
     using (var db = new CustomDatabase())
     {
         var audit = new AuthenticationAudit
         {
             Date     = DateTime.UtcNow,
             Activity = "Login Success",
             Detail   = null,
             ClientIP = HttpContext.Current.Request.UserHostAddress,
         };
         db.Audits.Add(audit);
         db.SaveChanges();
     }
 }