private void login() throws Exception {
   synchronized (Real_DebridFileRunner.class) {
     cz.vity.freerapid.plugins.services.real_debrid.Real_DebridServiceImpl service =
         (cz.vity.freerapid.plugins.services.real_debrid.Real_DebridServiceImpl)
             getPluginService();
     PremiumAccount pa = service.getConfig();
     if (!pa.isSet()) {
       pa = service.showConfigDialog();
       if (pa == null || !pa.isSet()) {
         throw new BadLoginException("No Real-Debrid account login information!");
       }
     }
     HttpMethod method =
         getMethodBuilder()
             .setAction(RD_LOGIN)
             .setParameter("user", pa.getUsername())
             .setParameter("pass", pa.getPassword())
             .setParameter("captcha_challenge", "")
             .setParameter("captcha_answer", "")
             .setParameter("time", "" + System.currentTimeMillis())
             .setBaseURL(RD_BASE_URL)
             .setReferer(RD_BASE_URL)
             .toGetMethod();
     if (!makeRedirectedRequest(method)) {
       throw new ServiceConnectionProblemException("Error posting login info");
     }
     if (getContentAsString().contains("Your login informations are incorrect")) {
       throw new BadLoginException("Invalid Real-Debrid account login information!");
     }
     final String auth = PlugUtils.getStringBetween(getContentAsString(), "cookie\":\"auth=", ";");
     addCookie(new Cookie(".real-debrid.com", "auth", auth, "/", 86400, false));
   }
 }
 protected boolean login() throws Exception {
   synchronized (getClass()) {
     final ForSharedServiceImpl service = (ForSharedServiceImpl) getPluginService();
     PremiumAccount pa = service.getConfig();
     if (!pa.isSet()) {
       pa = service.showConfigDialog();
       if (pa == null || !pa.isSet()) {
         LOGIN_CACHE.remove(getClass());
         throw new BadLoginException("No 4Shared account login information!");
       }
     }
     final LoginData loginData = LOGIN_CACHE.get(getClass());
     if (loginData == null || !pa.equals(loginData.getPa()) || loginData.isStale()) {
       logger.info("Logging in");
       doLogin(pa);
       final Cookie[] cookies = new Cookie[2];
       final Cookie loginCookie = getCookieByName("Login");
       final Cookie passwdCookie = getCookieByName("Password");
       if ((loginCookie == null) || (passwdCookie == null)) {
         throw new PluginImplementationException("Login cookies not found");
       }
       cookies[0] = loginCookie;
       cookies[1] = passwdCookie;
       LOGIN_CACHE.put(getClass(), new LoginData(pa, cookies));
     } else {
       logger.info("Login data cache hit");
       client.getHTTPClient().getState().addCookies(loginData.getCookies());
     }
     return true;
   }
 }
  private void doLogin(final PremiumAccount pa) throws Exception {
    HttpMethod method =
        getMethodBuilder()
            .setAction("https://www.4shared.com/web/login")
            .setAjax()
            .setParameter("returnTo", fileURL)
            .setParameter("login", pa.getUsername())
            .setParameter("password", pa.getPassword())
            .toPostMethod();
    if (!makeRedirectedRequest(method)) {
      throw new ServiceConnectionProblemException("Error posting login info");
    }
    if (getContentAsString().contains("Invalid e-mail address or password")) {
      throw new BadLoginException("Invalid 4Shared account login information");
    }

    // language is based on account pref,
    // setting language cookie doesn't work
    Cookie langCookie = getCookieByName("4langcookie");
    if ((langCookie == null) || !langCookie.getValue().equalsIgnoreCase("en")) {
      method =
          getMethodBuilder()
              .setAction(
                  "http://www.4shared.com/web/user/language") // set account's language preference
              .setParameter("code", "en")
              .toPostMethod();
      if (!makeRedirectedRequest(method)) {
        throw new ServiceConnectionProblemException();
      }
      if (!getContentAsString().contains("\"status\":\"ok\"")) {
        throw new PluginImplementationException("Setting language to EN failed");
      }
    }
  }
 @Override
 protected void doLogin(PremiumAccount pa) throws Exception {
   HttpMethod method =
       getMethodBuilder()
           .setReferer(getBaseURL())
           .setAction(getBaseURL() + "/login")
           .toGetMethod();
   if (!makeRedirectedRequest(method)) {
     throw new ServiceConnectionProblemException();
   }
   method =
       getMethodBuilder()
           .setReferer(getBaseURL() + "/login")
           .setAction(getBaseURL())
           .setActionFromFormByName("FL", true)
           .setParameter("login", pa.getUsername())
           .setParameter("password", pa.getPassword())
           .toPostMethod();
   if (!makeRedirectedRequest(method)) {
     throw new ServiceConnectionProblemException();
   }
   if (getContentAsString().contains("Incorrect Login or Password")) {
     throw new BadLoginException("Invalid account login information");
   }
 }