Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : HTTP username/password

www.cryer.info
Managed Newsgroup Archive

HTTP username/password

Subject:HTTP username/password
Posted by:"E Sterrett" (e_sterre..@mailinator.com)
Date:Sun, 24 Feb 2008 20:41:31

I have a very basic Indy 10 Http server (see below).

What would be the simplest way to add authentication. I don't need
multiple users, .htaccess, kerberos or anything like that. Just a simple
hard coded user:='admin'; password:='pass' example.

Thanks


program httpservertest;

{$APPTYPE CONSOLE}

uses
   HTTPApp,
   IdCustomHTTPServer,
   idcontext,
   idhttpserver,
   sysutils;

type
   TServer = class
     procedure httpServerCommandGet(AThread: TIdContext; RequestInfo:
TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
   end;

procedure TServer.httpServerCommandGet(AThread: TIdContext; RequestInfo:
TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
var
   html : String;
begin
   ResponseInfo.ContentType := 'text/HTML';
   html := '<html><head><title>Title</title></head><body>';
   html := html + '<center><h2>' + DateTimeToStr(Now)+ '</h2>';
   html := html + '<h2>Requested: ' + RequestInfo.Document + '</h2>';
   html := html + '<h2>Params: ' + RequestInfo.UnparsedParams + '</h2>';
   html := html + '</body></html>';
   ResponseInfo.ContentText := html;
end;

var
   Server:TServer;
   httpServer: TIdHTTPServer;

begin

   Server:=tserver.Create;
   httpserver:=tidhttpserver.Create();
   httpServer.OnCommandGet:=Server.httpServerCommandGet;
   httpServer.DefaultPort:=80;
   httpServer.Active:=true;

   while true do sleep(1000);

end.

Replies:

www.cryer.info
Managed Newsgroup Archive