public async Task <ApplicationUser> FindAsync(string userName, string password) { if (string.IsNullOrEmpty(userName)) { throw new ArgumentException(nameof(userName)); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException(nameof(password)); } var users = await _authContext.Users.Where(x => x.UserName == userName).ToListAsync(); return(users.FirstOrDefault(x => PasswordHasher.VerifyHashedPassword(x.Password, password))); }
public async Task UpdateAsync(UserDomain user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (user.Password != user.ConfirmPassword) { throw new InvalidOperationException("Password and confirmation password do not match"); } var existingUser = await GetByIdAsync(user.Id); if (existingUser == null) { throw new InvalidOperationException("user is not found"); } var isVerifiedPassword = PasswordHasher .VerifyHashedPassword(existingUser.Password, user.OldPassword); if (!isVerifiedPassword) { throw new InvalidOperationException("Incorrect password"); } if (user.Img != null && !user.Img.IsUrl()) { existingUser.Img = await ImageUploader.UploadAsync(user.Img); } existingUser.Email = user.Email; existingUser.UserName = user.UserName; existingUser.Password = PasswordHasher.HashPassword(user.Password); existingUser.Language = await _languageRepository.GetByLanguageTypeAsync(user.Language.LanguageType); await _authContext.SaveChangesAsync(); }