public async Task <RegistrationResult> RegisterAsync(string login, string password, string firstName, string lastName, string email) { if (userRepository.GetByAsync(u => u.Login == login).Result.Any()) { return new RegistrationResult { Success = false, Error = "User with same login already exists." } } ; if (password.Length < 6) { return new RegistrationResult { Success = false, Error = "Password should contains more than 6 symbols." } } ; var user = User.Insert(login, PasswordHashing.GetMd5Hash(password), firstName, lastName, email, Roles.User); await userRepository.InsertAsync(user); await userRepository.SaveChangesAsync(); return(new RegistrationResult { Success = true }); }
public async Task ChangePasswordAsync(int idUser, string oldPassword, string newPassword) { var user = await userRepository.GetAsync(idUser); if (user.Password != PasswordHashing.GetMd5Hash(oldPassword)) { throw new Exception("Wrong password."); } user.ModifyPassword(PasswordHashing.GetMd5Hash(newPassword)); await userRepository.SaveChangesAsync(); }