private async Task <Account> CreateAsync(Account item) { CheckBeforeCreate(item); var hashedPassword = _hashManager.Hash(item.Password); var account = AbstractionsConverter.ToAccount(item, hashedPassword); await _context.Accounts.AddAsync(account); await _context.SaveChangesAsync(); return(DataConverter.ToAccount(account)); }
private static void CheckAccount(DataModel.Account dbItem, string login, string password, IHashManager hashManager) { if (string.IsNullOrEmpty(login)) { throw new SecurityException(Resources.TextMessages.AccountEmptyLogin); } if (string.IsNullOrEmpty(password)) { throw new SecurityException(Resources.TextMessages.AccountEmptyPassword); } if (dbItem == null) { throw new SecurityException(Resources.TextMessages.AccountSomethingWrong); } var hashedPassword = hashManager.Hash(password, dbItem.Salt); if (hashedPassword?.HexHash != dbItem.Password) { throw new SecurityException(Resources.TextMessages.AccountSomethingWrong); } }