ID: Q140964
This article explains how to retrieve values for the user name and password in an ISAPI or CGI application.
The user name and password values can be retrieved in the ISAPI/CGI, according to the following rules.
The user name can only be retrieved when either Basic authentication scheme or Microsoft Windows NT Challenge/Response schemes are used. You can get the name by using the server variable, REMOTE_USER.
In ISAPI you can use GetServerVariable() API, and in CGI you can use getenv() C run-time function.
The following sample code can be used to get the server variable:
....
// This will fail with ERROR_INSUFFICIENT_BUFFER,
// since we supplied NULL buffer. As a result, dwLength will
// indicate the size of the buffer to allocate
if (!pECB -> GetServerVariable (pECB -> ConnID,
"REMOTE_USER",
NULL,
&dwLength) )
{
// Handle error other then ERROR_INSUFFICIENT_BUFFER here.
}
lpszVar= (CHAR *) LocalAlloc (LPTR, dwLen);
if ( !pECB -> GetServerVariable (pECB -> ConnID,
"REMOTE_USER",
lpszVar,
&dwLength))
{
// Handle error here
}
....
The user password can only be retrieved when Basic authentication scheme is used. The password is not available with the Windows NT Challenge/Response scheme, because the password never gets transmitted on the network.
To retrieve the password with the Basic authentication scheme, you need to parse it out from the HTTP_AUTHORIZATION server variable, which sets from HTTP Authorization header. HTTP_AUTHORIZATION has the following value:
Basic xxxxxxxxxxxxxxx
where Basic is an authentication scheme used, then it is followed by a
space, and "xxxxxxxxxxxxxxx" is UUENCODED string for "User-Name:User-
Password" pair separated by the semicolon.
Notes:
typedef struct _HTTP_FILTER_AUTHENT
{
CHAR * pszUser;
DWORD cbUserBuff;
CHAR * pszPassword;
DWORD cbPasswordBuff;
} HTTP_FILTER_AUTHENT, *PHTTP_FILTER_AUTHENT;
Keywords : kbnetwork iisapi
Version : 1.0
Platform : NT WINDOWS
Issue type : kbhowto
Last Reviewed: May 21, 1997