public static String GetAuthToken(String username, String password) {
        try {
            CookieManager m = new CookieManager();
            CookieHandler.setDefault(m);

            URL u3 = new URL("http://www.havenandhearth.com/portal/login");
            HttpURLConnection connection3 = (HttpURLConnection) u3
                    .openConnection();
            connection3.setDoOutput(true);
            connection3.connect();

            // read the result from the server
            BufferedReader rd3 = new BufferedReader(new InputStreamReader(
                    connection3.getInputStream()));
            StringBuilder sb3 = new StringBuilder();
            String line3;
            while ((line3 = rd3.readLine()) != null) {
                sb3.append(line3 + '\n');
            }

            String data2 = URLEncoder.encode("username", "UTF-8") + "="
                    + URLEncoder.encode(username, "UTF-8");
            data2 += "&" + URLEncoder.encode("password", "UTF-8") + "="
                    + URLEncoder.encode(password, "UTF-8");
            String data = "http://www.havenandhearth.com/portal/sec/login?r=/portal/";
            URL u1 = new URL(data);
            HttpURLConnection connection = (HttpURLConnection) u1
                    .openConnection();

            connection.setDoOutput(true);
            connection.connect();

            OutputStreamWriter wr = new OutputStreamWriter(
                    connection.getOutputStream());
            wr.write(data2);
            wr.flush();

            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = rd.readLine()) != null) {
                sb.append(line + '\n');
            }

            URL u2 = new URL("http://www.havenandhearth.com/portal/autohaven");
            HttpURLConnection connection2 = (HttpURLConnection) u2
                    .openConnection();

            connection2.setDoOutput(true);
            connection2.connect();
            BufferedReader rd2 = new BufferedReader(new InputStreamReader(
                    connection2.getInputStream()));
            StringBuilder sb2 = new StringBuilder();
            String line2;
            while ((line2 = rd2.readLine()) != null) {
                sb2.append(line2 + '\n');
            }
            String jnlp = sb2.toString();
            Pattern p = Pattern
                    .compile("<property name=\"haven.authck\" value=\"(.+)\" />");
            Matcher ma = p.matcher(jnlp);
            String token = null;
            if (ma.find()) {
                token = ma.group(1);
            }
            return token;
        } catch (Exception e) {
            return null;
        }
    }