HOWTO: Getting User Name and Password in ISAPI or CGI AppLast reviewed: May 20, 1997Article ID: Q140964 |
The information in this article applies to:
SUMMARYThis article explains how to retrieve values for the user name and password in an ISAPI or CGI application.
MORE INFORMATIONThe 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 allocateif (!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 xxxxxxxxxxxxxxxwhere 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:
|
Keywords : IISAPI kbnetwork
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |