Mega Code Archive

 
Categories / Delphi / Examples
 

Basic authentication in ISAPICGI applications

Title: Basic authentication in ISAPI/CGI applications Question: Question: How to password protect ISAPI/CGI actions with basic authentication? Answer: Answer: 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: Request.Authorization - 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)), mAuthorization); Have fun!