Author Topic: HTTP authenthication  (Read 700 times)

When accessing a website, it can show window asking for username and password authenthication.

How would I send user/pass information with TCPObjects?

When accessing a website, it can show window asking for username and password authentication.

How would I send user/pass information with TCPObjects?

I heard you can, although I don't actually know how. But I'm sure Truce will stumble drunken into here and draw up a masterpiece for you. :cookieMonster:

 :cookieMonster:. Anyway, I think that it's something with that I have to send login in headers, but hao :u

http://en.wikipedia.org/wiki/Basic_access_authentication

Quote
For example, given the user name 'Aladdin' and password 'open sesame', the string 'Aladdin:open sesame' is Base64 encoded, resulting in 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='.

Code: [Select]
GET /private/index.html HTTP/1.1
Host: localhost
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Though how to specifically use this information, I'm unsure.

Though how to specifically use this information, I'm unsure.

Here's me authenticating with my router:

Code: [Select]
function authConnection::onLine(%this,%line)
{
echo(%line);
}

function authConnection::onConnected(%this)
{
%this.send("GET /index.htm HTTP/1.1\r\n");
%this.send("Host: 10.0.0.1\r\n");
%this.send("Authorization: Basic ********\r\n");
%this.send("\r\n");
}

new TCPObject(authConnection);
authConnection.connect("10.0.0.1:80");

You would put your base64 encoded username / password combo where the asterisks are.



Just made a base64 conversion function (wow I feel smart):

Code: [Select]
function base64(%str)
{
%base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
%asciimap  = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN" @
             "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

%len = strLen(%str);

for(%i = 0; %i < %len; %i++)
{
%chr   = getSubStr(%str,%i,1);
%ascii = strPos(%asciimap,%chr) + 32;
%bin   = convertBase(%ascii,"0123456789","01");

while(strLen(%bin) < 8)
%bin = "0" @ %bin;

%all = %all @ %bin;
}

%len = strLen(%all);

for(%i = 0; %i < %len; %i += 6)
{
%pack = getSubStr(%all,%i,6);

while(strLen(%pack) < 6)
%pack = %pack @ "0";

%dec = convertBase(%pack,"01","0123456789");
%new = %new @ getSubStr(%base64map,%dec,1);
}

while(strLen(%new) % 4 > 0)
%new = %new @ "=";

return %new;
}

function convertBase(%val,%atype,%btype)
{
%vlen = strLen(%val);
%alen = strLen(%atype);
%blen = strLen(%btype);

for(%i = 0; %i < %vlen; %i++)
%sum += striPos(%atype,getSubStr(%val,%i,1)) * mPow(%alen,%vlen - %i - 1);

while(1)
{
%rem = %sum % %blen;
%new = getSubStr(%btype,%rem,1) @ %new;
%sum = mFloor(%sum / %blen);

if(!%sum)
break;
}

return %new;
}
« Last Edit: November 16, 2010, 04:10:32 PM by Truce »