| Blockland Forums > Modification Help |
| HTTP authenthication |
| (1/1) |
| Bauklotz:
When accessing a website, it can show window asking for username and password authenthication. How would I send user/pass information with TCPObjects? |
| MegaScientifical:
--- Quote from: Bauklotz on November 16, 2010, 08:37:31 AM ---When accessing a website, it can show window asking for username and password authentication. How would I send user/pass information with TCPObjects? --- End quote --- 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: |
| Bauklotz:
:cookieMonster:. Anyway, I think that it's something with that I have to send login in headers, but hao :u |
| Chrono:
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=='. --- End quote --- --- Code: ---GET /private/index.html HTTP/1.1 Host: localhost Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== --- End code --- Though how to specifically use this information, I'm unsure. |
| Truce:
--- Quote from: Chrono on November 16, 2010, 03:36:16 PM ---Though how to specifically use this information, I'm unsure. --- End quote --- Here's me authenticating with my router: --- Code: ---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"); --- End code --- You would put your base64 encoded username / password combo where the asterisks are. Just made a base64 conversion function (wow I feel smart): --- Code: ---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; } --- End code --- |
| Navigation |
| Message Index |