private void login(String uname, String pass)
	{
		if(KeyID == -5 || challstr == null)
			return;

		URL url = null;
		try 
		{
			url = new URL("https://play.pokemonshowdown.com/action.php");
		} 
		catch (MalformedURLException e) 
		{
			e.printStackTrace();
		}
        Map<String,Object> params = new LinkedHashMap<>();
        params.put("act", "login");
        params.put("name", uname);
        params.put("pass", pass);
        params.put("challengekeyid", KeyID);
        params.put("challenge", challstr);

        StringBuilder postData = new StringBuilder();
        byte[] postDataBytes = new byte[]{};
        for (Map.Entry<String,Object> param : params.entrySet()) 
        {
            if (postData.length() != 0) postData.append('&');
            try 
            {
				postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
				postData.append('=');
	            postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
	            postDataBytes = postData.toString().getBytes("UTF-8");
			} 
            catch (IOException e) 
            {
				e.printStackTrace();
			}
            
        }
        try
        {
	        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
	        conn.setRequestMethod("POST");
	        conn.addRequestProperty("User-Agent", 
	                "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0");

	        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	        conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
	        conn.setDoOutput(true);
	        conn.getOutputStream().write(postDataBytes);
	
	        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")));
	        String start = "";
	        while(in.hasNextLine())
	        {
	        	start += in.nextLine();
	        }
	        start = start.replaceFirst("]", "");
	        in.close();
	        JSONObject obj = null;
			try 
			{
				obj = (JSONObject) new JSONParser().parse(start);
			} 
			catch (ParseException e) 
			{
				e.printStackTrace();
			}
	        System.out.println(obj);
	        Object assertion = obj.get("assertion");
	        send("|/trn "+uname+",0,"+assertion);
        }
        catch(IOException ioe)
        {
        	ioe.printStackTrace();
        }
        loggedIn = true;
	}