2005. április 7., csütörtök
Basic authentication in ISAPI/CGI applications
Problem/Question/Abstract:
How to password protect ISAPI/CGI actions with basic authentication?
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);
Component Download: authen.zip
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése