public async Task <bool> ChangePassword(UserChangePassDTO userInfo) { using (_unitOfWork) { User user = await _unitOfWork.UserRepository.FindByID(userInfo.UserId); if (!PasswordEncryptionService.IsPasswordCorrect(user.Password, userInfo.OldPassword, _appSettings.SaltLength)) { return(false); } user.Password = PasswordEncryptionService.EncryptPassword(userInfo.NewPassword, _appSettings.SaltLength); _unitOfWork.UserRepository.Update(user); return(await _unitOfWork.Save()); } }
public async Task <UserAuthenticateResponseDTO> LogUserIn(UserLoginDTO userInfo) { using (_unitOfWork) { User user = await _unitOfWork.UserRepository.GetUserByUsername(userInfo.Username); if (user == null) { return(null); } if (!PasswordEncryptionService.IsPasswordCorrect(user.Password, userInfo.Password, _appSettings.SaltLength)) { return(null); } UserAuthenticateResponseDTO returnUser = _mapper.Map <User, UserAuthenticateResponseDTO>(user); returnUser.Token = _tokenManager.GenerateToken(user.UserId); returnUser.UnseenNotifications = _unitOfWork.UserRepository.GetUnseenNotificationNumber(user.UserId); return(returnUser); } }