private UserLoginEntity createUserLoginEntity(GuestDetails guestDetails) {
   UserLoginEntity entity = new UserLoginEntity();
   entity.setExpiresInMin(appConfig.getUserExpiredInMin());
   entity.setLoginFromIpAddress(guestDetails.getIpAddress());
   entity.setLoginTime(new Date());
   entity.setRequestToken(guestDetails.getRequestToken());
   entity.setStatus(StatusType.ACTIVE);
   entity.setLoginToken(userPasswordService.generateToken());
   entity.setUserAgent(guestDetails.getUserAgent());
   return entity;
 }
  /*
   * (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;
  }