Author Topic: Password Protected Web Connections  (Read 1009 times)

Can anyone explain to me (explain it, don't just yell out some extremely complicated code that makes my face sore) how to connect to a web page (using a TCPObject) that has a password on it, such as the site below
http://psp-networks.com/testing/

Thanks

your probably going to have to modify the HTTP Requests to include the password stuff.
gonna do some testing real quick, except a ton of requests.
yark, just kept on saying page not found.
just tried using a HTTPObject and it gave me some HTTP unauthorized. :| Sorry idk
« Last Edit: April 11, 2012, 09:00:29 PM by Brian Smithers »

If it's only basic authorization: use a TCPObject and send the "Authorization" header.

Authorization: Basic <base64 encoded user/pass pair>

Where <base 64 encoded user/pass pair> is the base 64 encode of the string <username>:<password>.

If it's only basic authorization: use a TCPObject and send the "Authorization" header.

Authorization: Basic <base64 encoded user/pass pair>

Where <base 64 encoded user/pass pair> is the base 64 encode of the string <username>:<password>.

Again, not good with TCP. Where should I put this?
Also, how do I get the base64 encoded string?


new TCPObject(blah);
blah.connect("url:80");
%header = "GET /index.html HTTP/1.0\r";
%header = %header NL "Authorization: Basic " @ base64("username:password") @ "\r\n";
blah.send(%header);

this is like a torque psuedo code sort thing. There aren't the exact function names and this isn't the exact headers, but it's a good idea of what it should look like.

Fixed kalph
« Last Edit: April 11, 2012, 11:26:56 PM by Brian Smithers »


Base64 code courtesy of Truce:
Code: [Select]
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;
}
function base64Encode(%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 base64Decode(%str)
{
%base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
%asciimap  = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN" @
            "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

while(getSubStr(%str,strLen(%str) - 1,1) $= "=")
%str = getSubStr(%str,0,strLen(%str) - 1);

%len = strLen(%str);

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

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

%all = %all @ %bin;
}

while(strLen(%all) % 8 > 0)
%all = getSubStr(%all,0,strLen(%all) - 1);

%len = strLen(%all);

for(%i = 0; %i < %len; %i += 8)
{
%bin = getSubStr(%all,%i,8);
%dec = convertBase(%bin,"01","0123456789") - 32;
%chr = getSubStr(%asciiMap,%dec,1);

%new = %new @ %chr;
}

return %new;
}
Example TCP code:
Code: [Select]
new TCPObject(test);

$domain = "psp-networks.com";
$user = "some_username";
$pass = "some_password";
$headers = "GET /testing HTTP/1.1\r\n" @
                     "Host: " @ $domain @ "\r\n" @
                     "Authorization: Basic " @ base64Encode($user @ ":" @ $pass) @ "\r\n\r\n";

test.connect(%domain @ ":80");

function test::onConnected(%this) {
test.send($headers);
}
function test::onLine(%this, %line) {
echo(%line);
}
(not tested, should work fine though)
« Last Edit: April 12, 2012, 07:14:11 AM by Destiny/Zack0Wack0 »

Code: [Select]
new TCPObject(test);

$domain = "psp-networks.com";                                  // Global variables.
$user = "some_username";
$pass = "some_password";
$headers = "GET /testing HTTP/1.1\r\n" @
                     "Host: " @ %domain @ "\r\n" @             // Local variables?
                     "Authorization: Basic " @ base64Encode(%user @ ":" @ %pass) @ "\r\n\r\n";

test.connect(%domain @ ":80");

function test::onConnected(%this) {
test.send($headers);
}
function test::onLine(%this, %line) {
echo(%line);
}

Uh, what?