java - login to forum - networking

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 7806 Views - Last Post: 03 September 2010 - 10:51 PM Rate Topic: -----

#1 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

java - login to forum - networking

Posted 26 August 2010 - 05:29 AM

How do I code a program that logs in to a forum (or any website) using a valid account?
Provide some links / examples thanks

edit: log in to forums / megaupload

This post has been edited by BlueSpinz: 26 August 2010 - 06:34 AM

Is This A Good Question/Topic? 0
  • +

Replies To: java - login to forum - networking

#2 m-e-g-a-z   User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,457
  • Joined: 19-October 09

Re: java - login to forum - networking

Posted 26 August 2010 - 05:47 AM

You may want to check out Martyr2's blog post Login to a Website from Java.
Was This Post Helpful? 0
  • +
  • -

#3 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

Re: java - login to forum - networking

Posted 26 August 2010 - 06:33 AM

Doesn't work...
Was This Post Helpful? -3
  • +
  • -

#4 m-e-g-a-z   User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,457
  • Joined: 19-October 09

Re: java - login to forum - networking

Posted 26 August 2010 - 06:42 AM

Saying it doesn't work wont help, post your code for us to debug your problem.
Was This Post Helpful? 2
  • +
  • -

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: java - login to forum - networking

Posted 26 August 2010 - 04:14 PM

View PostBlueSpinz, on 26 August 2010 - 07:33 AM, said:

Doesn't work...

What a useless answer
What did you tried ?
Let us check if you followed Martyr2 magic receipy
Was This Post Helpful? 0
  • +
  • -

#6 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

Re: java - login to forum - networking

Posted 29 August 2010 - 12:16 AM

View Postpbl, on 26 August 2010 - 03:14 PM, said:

View PostBlueSpinz, on 26 August 2010 - 07:33 AM, said:

Doesn't work...

What a useless answer
What did you tried ?
Let us check if you followed Martyr2 magic receipy


In the code at

Quote


All I have to do is replace the examplesite with the login url of the forum and replace MyUsername/MyPassword with the login/pass?
What is the forum doesn't have a login.php... it redirects to the main page...
Was This Post Helpful? 0
  • +
  • -

#7 guahguahmonster   User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: java - login to forum - networking

Posted 29 August 2010 - 01:44 AM

View PostBlueSpinz, on 29 August 2010 - 01:16 AM, said:

In the code at

Quote


All I have to do is replace the examplesite with the login url of the forum and replace MyUsername/MyPassword with the login/pass?
What is the forum doesn't have a login.php... it redirects to the main page...


Well, that depends. You need to look at the forum and find its login form. You'll need to look at the URL that the form submits to (its action attribute). Then you need to figure out what the names of its username and password fields are. If they aren't username and pass, then you'll need to change those names in your query string (line 30 of the example), in addition to the username/password you actually want to log in with.
Was This Post Helpful? 0
  • +
  • -

#8 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

Re: java - login to forum - networking

Posted 29 August 2010 - 03:04 AM

How do I do that?

I found this in the html of a forum.
				<!-- login form --> 
					<form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)"> 
					<script type="text/javascript" src="clientscript/vbulletin_md5.js?v=3611"></script> 
					<table cellpadding="0" cellspacing="3" border="0"> 
					<tr> 
						<td class="smallfont"><label for="navbar_username">User Name</label></td> 
						<td><input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" /></td> 
						<td class="smallfont" colspan="2" nowrap="nowrap"><label for="cb_cookieuser_navbar"><input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" />Remember Me?</label></td> 
					</tr> 
					<tr> 
						<td class="smallfont"><label for="navbar_password">Password</label></td> 
						<td><input type="password" class="bginput" style="font-size: 11px" name="vb_login_password" id="navbar_password" size="10" tabindex="102" /></td> 
						<td><input type="submit" class="button" value="Log in" tabindex="104" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" /></td> 
					</tr> 
					</table> 
					<input type="hidden" name="s" value="" /> 
	<input type="hidden" name="securitytoken" value="291a3f252ee603dfd2a46c9328a19d82a56d5500" /> 
					<input type="hidden" name="do" value="login" />		
					<input type="hidden" name="vb_login_md5password" /> 
					<input type="hidden" name="vb_login_md5password_utf" /> 
					</form> 
					<!-- / login form --> 


Is that useful? What do I do from here...

This post has been edited by macosxnerd101: 29 August 2010 - 08:33 AM
Reason for edit:: Please use CODE tags, not QUOTE tags when posting code.

Was This Post Helpful? 0
  • +
  • -

#9 nick2price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: java - login to forum - networking

Posted 29 August 2010 - 06:06 AM

Havnt checked out Martyr2's blog, but the redirect url of your forum form is
login.php


Remember though, if you are doing this, the url will need to be absolute. So, if this was for this forum, the url you would need to provide would be
www.dreamincode.net/login.php


The names of the form are
navbar_username
navbar_password

Was This Post Helpful? 0
  • +
  • -

#10 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

Re: java - login to forum - networking

Posted 29 August 2010 - 07:05 AM

Let's say I want to login here: http://forums.steamp...orums/login.php

    
public void connect() {

        try {
            // Establish a URL and open a connection to it. Set it to output mode.
            URLObj = new URL("http://forums.steampowered.com/forums/login.php");
            connect = URLObj.openConnection();
            connect.setDoOutput(true);
            // Create a buffered writer to the URLConnection's output stream and write our forms parameters.
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream()));
            writer.write("navbar_username=<MYUSERNAME>&navbar_password=<MYPASSWORD>&submit=login");
            writer.close();

            // Now establish a buffered reader to read the URLConnection's input stream.
            BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
            String lineRead = "";
            while ((lineRead = reader.readLine()) != null) {
                System.out.println(lineRead);
            }
            reader.close();
        } catch (Exception ex) {
            System.out.println("There was an error reading or writing to the URL: " + ex.getMessage());
        }
    }



This is my code. It doesn't seem to work. Why?

This post has been edited by BlueSpinz: 29 August 2010 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#11 nick2price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: java - login to forum - networking

Posted 29 August 2010 - 08:08 AM

Sorry, the fields should be
vb_login_username
vb_login_password


Do you get any errors or anything, or it just doesnt work? Additionally, the url dont seem to want to take you to the php file, so I dont know if they have some security on this. Maybe you should try a different forum.
Was This Post Helpful? 0
  • +
  • -

#12 guahguahmonster   User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: java - login to forum - networking

Posted 29 August 2010 - 08:56 AM

Well, I notice that they do something funky with their onsubmit action, and additionally they submit to login.php?do=login. Not sure if the GET query string is significant, nor what that md5hash function does. You can use some Firefox extension to determine exactly what request headers your browser sends when you login via browser, and emulate that as closely as you can until it works.
Was This Post Helpful? 0
  • +
  • -

#13 BlueSpinz   User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 34
  • Joined: 17-August 10

Re: java - login to forum - networking

Posted 30 August 2010 - 05:01 AM

What about megaupload?


HTML of login function:
function postlogin()
{
  if(document.getElementById('username').value == '')
  {
	
	document.getElementById('username').focus();
	alert('Please enter your username.');
	
  }
  else if(document.getElementById('password').value == '')
  {
	
	document.getElementById('password').focus();
	alert('Please enter your password.');
	
  }
  else
  {
	document.getElementById('loginfrm').submit();
  }
 
 
}



    public void connect() {

        try {
            // Establish a URL and open a connection to it. Set it to output mode.
            URLObj = new URL("http://megaupload.com/?c=login");
            connect = URLObj.openConnection();
            connect.setDoOutput(true);
            // Create a buffered writer to the URLConnection's output stream and write our forms parameters.
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream()));
            writer.write("username=USER&password=PASSWORD&submit=login");
            writer.close();

            // Now establish a buffered reader to read the URLConnection's input stream.
            BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
            String lineRead = "";
            while ((lineRead = reader.readLine()) != null) {
                System.out.println(lineRead);
            }
            reader.close();
        } catch (Exception ex) {
            System.out.println("There was an error reading or writing to the URL: " + ex.getMessage());
        }
    }


That too doesn't work

This post has been edited by BlueSpinz: 30 August 2010 - 05:01 AM

Was This Post Helpful? -2
  • +
  • -

#14 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12360
  • View blog
  • Posts: 45,473
  • Joined: 27-December 08

Re: java - login to forum - networking

Posted 30 August 2010 - 05:07 AM

Mechanic, here is my car, it is broken. Really, what's wrong with it? It doesn't work.

This does not help us at all. Tell us specifically the problem or error and make an effort at debugging. We are happy to help, but until you tell us the error, we are the blind leading the blind.
Was This Post Helpful? 1
  • +
  • -

#15 guahguahmonster   User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: java - login to forum - networking

Posted 30 August 2010 - 10:46 AM

I looked at megaupload's login form. They have two hidden fields in that form. Replicate those fields and their values in your POST query, and see if that changes anything.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2