Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / Objective C

ISAPI Authentication Filter

Rate me:
Please Sign up or sign in to vote.
3.25/5 (5 votes)
6 Dec 1999CPOL 295.9K   2.4K   44   56
This article demonstrates the use of the MFC ISAPI classes to write filters.

In this article, the Microsoft SDK ISAPI authentication filter sample was rewritten using MFC ISAPI classes. The filter's functionality remains exactly the same, the purpose of the article is to demonstrate the use of the MFC ISAPI classes to write filters. Note that this authentication filter is not the most trivial sample, it provides pretty serious functionality (Microsoft refers to it as "A Filter for Advanced Authentication"). The filter functionality is described below using an exception of Microsoft documentation.

"AuthFilt demonstrates how to write an authentication filter based on an external datasource. Authentication is the process of accepting or denying a request from a client, so AuthFilt will be notified each time an authentication request comes in. This sample uses a file (userdb.txt) to keep track of authorized users, but you might modify this sample to access a database which holds user information.

For each authentication request, AuthFilt first looks in a cache of recently authenticated users, and when that fails, AuthFilt looks in the userdb.txt file. This shows an efficient way to authorize connections: a cache allows the filter to quickly authenticate users, and because each request comes in through the filter, speed is critical."

The project is a standard appwizard generated ISAPI filter. The global functions of the AuthFilt Microsoft sample were encapsulated in the filter class. There are 3 parameters that can be changed to fine tune the filter: the maximum number of cached users, the position after which a cached entry will be moved to the front of the list (to make the search time shorter!) and the name of the file that contains the username/password pairs and the appropriate NT account the username/password should be mapped to. All these parameters are #define directives in the authflit.h header file.

The filter could be improved in several ways: using a database instead of a file for authentication information (you should consider using stored procedures to search and/or to cache!), load parameters from registry, automatic selection of the number of cached users and the list reorder parameter, etc.

The full source code is provided, you will have to compile it in order to get a working filter. Once you have compiled the project, you will need to take the following steps to install:

  1. Run REGEDT32.EXE and modify the server's registry as follows. Select the Filter DLLs key in HKEY_LOCAL_MACHINE\CurrentControlSet\Services\W3SVC\Parameters. Add a local path to authfilt.dll, usually C:\WinNT\System32\InetSrv\authfilt.dll. The filter entries are separated by commas. The order is important, if you have other authentication filter with the same priority, the first one listed will receive the authentication request.
  2. Copy the authfilt.dll file to the directory you specified in the registry.
  3. Make sure the System account has execute rights on the filter DLL file.
  4. Edit the userdb.txt file so it contains valid users and passwords. The format of the file is:
    User1:Password1, NTUser1:NTPassword1
    User2:Password2, NTUser2:NTPassword2
    User3:Password3, NTUser3:NTPassword3
  5. Copy the userdb.txt file to the directory you specified in the authfilt.h header file for the user database.
  6. Make sure the System account has read rights on the userdb.txt file.
  7. Restart the WWW service.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Cuba Cuba
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralForm based authentication Pin
5-Feb-02 22:33
suss5-Feb-02 22:33 
GeneralRe: Form based authentication Pin
Bob Cowdery6-Feb-02 2:18
Bob Cowdery6-Feb-02 2:18 
GeneralIIS Filter & Cookie Pin
18-Oct-01 7:31
suss18-Oct-01 7:31 
Generalcache Pin
18-Oct-01 3:37
suss18-Oct-01 3:37 
GeneralRe: cache Pin
16-Oct-02 11:21
suss16-Oct-02 11:21 
GeneralAuthfilt.dll & IIS problem Pin
21-Sep-01 11:13
suss21-Sep-01 11:13 
GeneralRe: Authfilt.dll & IIS problem Pin
12-Jun-02 10:18
suss12-Jun-02 10:18 
Questionisapi filter ? Pin
8-Aug-01 15:36
suss8-Aug-01 15:36 
AnswerRe: isapi filter ? Pin
9-Sep-01 18:47
suss9-Sep-01 18:47 
GeneralDistributing SSL cert's Pin
11-Jun-01 10:12
suss11-Jun-01 10:12 
GeneralCan't get it to work Pin
7-Jun-01 3:50
suss7-Jun-01 3:50 
GeneralRe: Can't get it to work Pin
ThatInstant12-Dec-03 8:46
ThatInstant12-Dec-03 8:46 
GeneralIs it possible One directory, one diferent ACL? (as Apache) Pin
23-Feb-01 2:02
suss23-Feb-01 2:02 
GeneralRe: Is it possible One directory, one diferent ACL? (as Apache) Pin
9-Oct-01 2:55
suss9-Oct-01 2:55 
GeneralAuthentication from database Pin
bill robinson28-Jul-00 10:55
bill robinson28-Jul-00 10:55 
GeneralRe: Authentication from database Pin
5-Feb-01 0:00
suss5-Feb-01 0:00 
GeneralRe: Authentication from database Pin
14-Apr-02 20:01
suss14-Apr-02 20:01 
QuestionWhy map to NT account? Pin
Scott4-Jul-00 20:24
Scott4-Jul-00 20:24 
AnswerRe: Why map to NT account? Pin
25-Jan-01 15:24
suss25-Jan-01 15:24 
GeneralRe: Why map to NT account? Pin
21-Feb-01 21:49
suss21-Feb-01 21:49 
GeneralRe: Why map to NT account? Pin
17-Apr-01 3:43
suss17-Apr-01 3:43 
Generalauthentication with LDAP Pin
Daniele Speziale6-Jun-00 21:13
Daniele Speziale6-Jun-00 21:13 
GeneralRe: authentication with LDAP Pin
5-Sep-01 13:13
suss5-Sep-01 13:13 
GeneralRe: authentication with LDAP Pin
13-Apr-02 1:12
suss13-Apr-02 1:12 
GeneralRe: authentication with LDAP Pin
14-May-02 5:37
suss14-May-02 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.