/*
   * (non-Javadoc)
   *
   * @see org.hamster.sprite.service.user.UserLoginService#userLogin(java.lang.String, java.lang.String,
   * org.hamster.sprite.service.user.dto.GuestDetails)
   */
  @Override
  public UserLoginEntity userLogin(String userId, String password, GuestDetails guestDetails) {
    UserEntity user = findUser(userId);
    if (user == null) {
      throw Exceptions.USRC001.create(null, userId);
    }

    String hashedPassword =
        userPasswordService.hashPassword(password, ByteSource.Util.bytes(user.findSalt()));

    if (!hashedPassword.equals(user.getPassword())) {
      throw Exceptions.USRC002.create(null);
    }

    UserLoginEntity loginEntity = createUserLoginEntity(guestDetails);
    user.getLogins().add(loginEntity);
    userRepository.save(user);

    return loginEntity;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.hamster.sprite.service.user.UserLoginService#findUser(java.lang.String)
  */
 @Override
 public UserEntity findUser(String userId) {
   return userRepository.findByUserId(userId);
 }