private async Task <Data.Account> GetValidAccountAsync(Credentials creds) { Data.Account account = await _store.LoadByToken(creds.Username); if (account == null) { throw new AuthenticationFailureException(); } if (account.Status == AccountStatus.Disabled) { throw new AccountDisabledException(); } if (account.IsLocked()) { string duration = account.LockDurationSeconds().ToString(); throw new AccountLockedException(duration); } if (account.HasExpiredPassword(_options.Password.Age)) { throw new PasswordExpiredException(); } if (!account.VerifyPassword(creds.Password)) { account.Lock(_options.Authentication.LockThreshold); await _store.Update(account); throw new AuthenticationFailureException(); } return(account); }