public void SaveAccount(string passwordHash, AccountConfiguration accountConfiguration) { var accounts = GetAccounts(); if (accounts == null) { throw new NullReferenceException(nameof(accounts)); } var accountId = accountConfiguration.AccountId; var account = accounts?.Accounts?.FirstOrDefault(a => a.AccountId == accountId); if (account != null) { if (!Security.IsPasswordValid(passwordHash, account.Password)) { throw new SecurityException("Bad password"); } } EncryptWallets(passwordHash, accountConfiguration.Wallets); var list = accounts?.Accounts?.ToList() ?? new List <AccountConfiguration>(); list.RemoveAll(a => a.AccountId == accountConfiguration.AccountId); list.RemoveAll(a => a.UserName.ToLower() == accountConfiguration.UserName.ToLower()); list.Add(accountConfiguration); accounts.Accounts = list.ToArray(); SaveAccounts(accounts); DecryptWallets(passwordHash, accountConfiguration.Wallets); }
public void ValidateAccount(AccountConfiguration account, string passwordHash) { if (!Security.IsPasswordValid(passwordHash, account.Password)) { throw new SecurityException("Password or username is invalid"); } }