using t0mm0 net.http_POST for login form

The_Silencer

Developer
Jan 29, 2013
48
0
0
N/A
I want to make sure I am trying to sending the right information:

If the login form on the site is:

Code:
<form action="http://www.Al*uc.to/index.php" method="post">
    <input name="pageid" value="22" type="hidden">
    <input name="sid" value="f589e276af6df23d824b6547f1451f34" type="hidden">
    <input name="action" value="login" type="hidden">
    <input name="navpath" value="{NAVIGATIONHISTORY}" type="hidden">
  
	<table align="center">
			<tbody><tr>
				<td colspan="2" align="center">
					<h3 style="font: 14px Arial;"><b>Please Login</b></h3>
				</td>
			</tr>
			<tr>
				<td> 
					Username:
				</td>
				<td>
					<input name="loginid" value="" onfocus="if (this.value==this.defaultValue){ this.value=''; this.style.color = '#000000';}" style="width:163px; height:15px;color:#c0c0c0; border:solid 1px #A0A0A0; font-size:11px;" type="text"><br>
				</td>
			</tr>
			<tr>
				<td> 
					Password:
				</td>
				<td> 
					<input name="passwd" id="pass" onfocus="if (this.value==this.defaultValue){ this.value=''; this.style.color = '#000000';}" value="Passwort" style="width:143px; height:15px;color:#c0c0c0; background-color:#FFFFFF; border:solid 1px #A0A0A0; font-size:11px;" type="password"><input name="image" title="Login" src="/images/login.gif" style="position:absolute;margin-top:0px;" type="image"><br>
				</td>
			</tr>
			<tr>
				<td>
					 
				</td>
				<td>
					<input name="remember" value="1" style="height:18px;" checked="" type="checkbox"> Remember me
				</td>
I am using: form = {'action': 'login', 'loginid': loginid, 'passwd': passwd, 'remember':'on'}


Am I flagging the correct information in the form?
 

the-one

Banned
May 7, 2013
189
0
0
New Jersey, USA
The form is using a lot of hidden fields. you should add hidden fields as well.

From what you have posted, below should work.

{'action': 'login', 'loginid': loginid, 'passwd': passwd, 'remember':'1', 'pageid':'22', 'sid' : 'f589e276af6df23d824b6547f1451f34'}
 

The_Silencer

Developer
Jan 29, 2013
48
0
0
N/A
The form is using a lot of hidden fields. you should add hidden fields as well.

From what you have posted, below should work.

{'action': 'login', 'loginid': loginid, 'passwd': passwd, 'remember':'1', 'pageid':'22', 'sid' : 'f589e276af6df23d824b6547f1451f34'}
Thank you the-one, if I need to pass the 'sid' I will capture that before I send the information it changes.

I will scrape and capture the sid from the page then name it sid,
I will end up with:
{'action': 'login', 'loginid': loginid, 'passwd': passwd, 'remember':'1', 'pageid':'22', 'sid' : sid}

Thank you again, I am going to work on this.
 

The_Silencer

Developer
Jan 29, 2013
48
0
0
N/A
log in is working my problem was a noob mistake (almost drove me crazy). After you log in and store your cookie make sure to USE that cookie when you try to scrape the pages behind authentication.

I will break down this learning experience, maby help someone in the future:

When you want to use t0mm0 net.http_POST for log in form search for the post area on the log in page

Example:
Code:
<form action="http://www.Al*uc.to/" method="post">
			<input name="pageid" value="5" type="hidden">
			<input name="sid" value="5df2ab2e698ee6842a25e0fc7e59fb22" type="hidden">
			<input name="sysparam" value="" type="hidden">
			<input name="action" value="login_out_box" type="hidden">
			<input name="data" value="" type="hidden">
			<div style="margin:auto;width:160px;float:none">
				<span style="font-weight:bold; text-transform: uppercase;">Username</span>
				<br>
				<input name="loginid" value="" onfocus="if (this.value==this.defaultValue){ this.value=''; this.style.color = '#000000';}" style="width: 154px; height: 15px; color: rgb(0, 0, 0); border: 1px solid rgb(160, 160, 160); font-size: 11px;" type="text">
				<br>
				<div style="float:none; font-weight:bold; margin-top:8px; text-transform: uppercase;">Password</div>
				<input name="passwd" onfocus="if (this.value==this.defaultValue){ this.value=''; this.style.color = '#000000';}" value="Passwort" style="width: 154px; height: 15px; color: rgb(192, 192, 192); background-color: rgb(255, 255, 255); border: 1px solid rgb(160, 160, 160); font-size: 11px;" type="password">
				<br>
				<input name="remember" value="1" style="margin-top: 4px;margin-left: 25px;vertical-align: sub;" checked="checked" type="checkbox">
				<span style="font-size:11px;font-weight:bold; text-transform: uppercase;">Remember me</span><br>
Try to send back all the input fields you can, only tricky one on this form was the: <input name="sid" value="5df2ab2e698ee6842a25e0fc7e59fb22" type="hidden"> it changed with each page load. "notice the FINDSID(url) used to capture the sid for the page load.

Code I used:
Code:
#Al*uc Logon
def FINDSID(url):
        content = net.http_GET(url).content
        match=re.search('<input type="hidden" name="pageid" value="5" />\r\n\t\t<input type="hidden" name="sid" value="(.+?)" />\r\n\t\t<input type="hidden" name="sysparam" value="" />', content) #<input type="hidden" name="sid" value="(.+?)"
        return match.group(1)

def LoginStartup():
        Al*uc_account = local.getSetting('Al*uc-account')
        if Al*uc_account == 'true':
                loginurl = Al*uc_URL
                login = local.getSetting('Al*uc-username')
                password = local.getSetting('Al*uc-password')
                
                sid = FINDSID(loginurl)
                form = {'action' : 'login_out_box', 'loginid' : login, 'passwd' : password, 'remember' : '1', 'pageid' : '5', 'sid' : sid}
                net.http_POST(loginurl, form)
                net.save_cookies(cookiejar)
The form area is the input information for your log in form.

ALWAYS remember once you log in correctly and save your cookie use it....
Code:
#Login Check
def INDEX1(url):
        net.set_cookies(cookiejar)
        req = urllib2.Request(url)
        req.add_header('User-Agent', USER_AGENT)
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('href="/logout.html">Logout (.+?)</a>').findall(link)
        for name in match:
               addDir('Logged in as:'+name,url,18,'',None,None)
Thanks again the-one, the support here at the HUB is the best:

--Remember-- to everyone trying to learn how to write an add-on never give up, even if takes 2 days to figure out you were not using one line of code "net.set_cookies(cookiejar)"