public void SaveUserCredentials(UserCredential userCred) { var user = _unitOfWork.Users.GetBy(userCred.UserId); if (user == null) { throw new UserNullException($"User not found with id {userCred.UserId}"); } if (userCred != null) { var userCredentialSpec = new UserCredentialSpecification(); if (!userCredentialSpec.IsSatisfiedBy(userCred)) { throw new NullReferenceException("Username/Password cannot be null."); } var result = PasswordService.HashPassword(userCred.Password); userCred.Password = result.HashedPassword; userCred.SetKey(user, result.SaltKey); user.Credentials = userCred; } }