public boolean authenticate() throws SessionException, IOException, GatewayValidationException {

        if (!session_mode) {
            throw new SessionException("This function can only be called when Session Mode is enabled.");
        }
        URL obj = new URL(URL + "auth?api_id=" + api_id + "&user=" + user + "&password=" + password);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        int responseCode = con.getResponseCode();
        if (responseCode == 200) {
            StringBuilder response;
            try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
                String inputLine;
                response = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                session_id = response.substring(4);
                return true;
            }
        } else {
            ErrorCode e = new ErrorCode(responseCode);
            throw new GatewayValidationException(e.getErrorDescription());
        }
    }