Basic authentication in ISAPI/CGI applications (Views: 101)


How to password protect ISAPI/CGI actions with basic authentication?


It is very easy to protect a web server virtual directory with basic authentication.
Supose you have an ISAPI application with 3 actions and you want to password protect only one of them. This example shows you how you could do that with only one ISAPI application.

Source Code:

- This 2 lines tells browser to prompt for user name and password:

Response.StatusCode := 401; // Promp for user name and password
Response.WWWAuthenticate := 'Basic realm="Delphi"'; // Title

- Browser sends user name and password and we can get it:


- But information is encoded with Base64. There a lot of free source code that implements Base64 encode/decode. The following line returns decoded data in mAuthorization.

FBase64.DecodeData(Copy(Request.Authorization, 6, Length(Request.Authorization)),

Component Download: authen.zip

<< Back to main page