Click here to Skip to main content
Licence 
First Posted 8 Oct 2003
Views 238,804
Bookmarked 53 times

Web-based Active Directory Login

By | 9 Oct 2003 | Article
Web-based Active Directory Login

Overview

Web-based Active Directory Login implements central sign-on system for web-based applications. It was developed to eliminate maintenance of user passwords in database, whether encrypted or not. A user running application from desktop enjoys liberty to access resources and/or services on the network which he has permission to do from Windows. On the other hand, web-based applications run in a security context entirely different from that of a desktop application. Same user while running application from browser will not have such liberty. This was the problem when I tried to login using my n/w user name and password maintained in Active Directory through web. Ultimately it was overcome by impersonating the web server anonymous user which in most cases is IUSR_machinename.

Using the code

Below is a brief description of how to use the code.

There are two class files

  1. LoginAdmin
  2. prjLogin

LoginAdmin is an ActiveX DLL type project and contains a standard module and a class module. The ImpersonateUser class has two methods which you will be using in your ASP code.

' create an object of ImpersonateUser class
 Set objLogon = Server.CreateObject("LoginAdmin.ImpersonateUser")
 
' any domain user who has rights to access active directory
 objLogon.Logon "user id", "password", "domain name"

 objLogon.Logoff
 Set objLogon = Nothing

These are the methods of the class ImpersonateUser and their description:

Method Description
Logon(strUser, strPassword, strDomain) This method should be called before sending request to active directory. The user should be a valid domain user with at least read permissions of active directory. You can keep this user in a database or hardcode it's userid and password in the ASP script.
LogOff() This method must be called after accessing info from Active Directory in order for IIS to revert security permissions of the particular file

prjLogin is also an ActiveX DLL type project and contains only a class module. It uses references to Active DS type library. The clsDomainLogin class has one method with three parameters user name, password and domain.

' create an object of clsDomainLogin class
 Set oUser = Server.CreateObject("prjLogin.clsDomainLogin")

' BindObject has three parameters userid, password and domain name
 iResult = oUser.BindObject(strUser, strPassword, strDomain)

Below is a method of the class clsDomainLogin and its description:

Method Description
BindObject(strUser, strPassword, strDomain) This method should be called while authenticating from Active Directory. It returns 1 when successful and 0 when unsuccessful

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Faisal Haroon

Web Developer
The Shams Group
Pakistan Pakistan

Member

Faisal is Senior Team Lead at The Shams Group, Karachi. He has 10+ years of experience in the field of software/ web development and infrastructure management.
He has worked on various tools and platform which includes VB, ASP, ASP.NET, Javascript, COM/COM+, SQL Server, Informix, Active Directory, UNIX/Solaris, WSH, Windows NT/ 2000 servers, RADIUS, SMTP, POP, IMAP etc.
He likes to watch movies, hangs out with friends and loves to make new friends.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionCan you help me!!! PinmemberSawan4:48 19 Oct '11  
GeneralThank you VERY much !!! Pinmemberaurelian650:56 14 Apr '11  
GeneralOnly look in certain Active Directory OU Pinmembermmora571810:14 10 Sep '10  
QuestionWhy only 1 wrong password try locks out my Network ID? PinmemberRed Valdez23:42 16 Jun '09  
GeneralASPX Web-based Active Directory Login problem Pinmemberra2ak0:35 8 May '09  
GeneralRe: ASPX Web-based Active Directory Login problem PinmemberRed Valdez23:40 16 Jun '09  
GeneralLogin success / bad password, when using no un / pw or a correct un / pw Pinmembergraeme thompson2:37 23 Apr '09  
GeneralRe: Login success / bad password, when using no un / pw or a correct un / pw Pinmemberaurelian651:04 14 Apr '11  
GeneralFANTASTIC. THANK YOU!!! Pinmemberdickpacific7:31 13 Feb '09  
GeneralWorks perfect in WINXP Web Server but won't work with WINDOWS 2003 64-bit machine PinmemberMember 31847143:19 15 Jul '08  
GeneralRe: Works perfect in WINXP Web Server but won't work with WINDOWS 2003 64-bit machine PinmemberFaisal Haroon6:32 29 Jul '08  
GeneralRe: Works perfect in WINXP Web Server but won't work with WINDOWS 2003 64-bit machine PinmemberRed Valdez23:00 17 Feb '09  
QuestionHow to use functions in dynamic stored procedures Pinmembersanjeev Kumar Gupta23:40 7 Aug '07  
Generallogon failed to active directory with ASP Pinmemberfernandoariel9:01 25 Apr '07  
GeneralRe: logon failed to active directory with ASP Pinmemberaurelian651:06 14 Apr '11  
GeneralImpersonateUser in IIS6.0 PinmemberAugusto Ortiz13:33 15 Mar '07  
GeneralNo changes and 529 errors PinmemberMember #38334928:33 15 Feb '07  
QuestionVS 2005 ASP.NET error PinmemberPeter Grigg19:26 4 Sep '06  
I tried your demo project on a Windows XP machine with VS 2005 installed, is that why I'm getting the following error:
 
Server Error in '/testADlogin' Application.
--------------------------------------------------------------------------------
 
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden.   The extension '.asp' may be incorrect.   Please review the URL below and make sure that it is spelled correctly.
 
Requested URL: /testADlogin/login.asp
 

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
 
Peter
AnswerRe: VS 2005 ASP.NET error PinmemberFaisal Haroon3:45 2 Nov '06  
GeneralPorts and Protocols PinmemberRicardo Gimenez7:33 4 Sep '06  
QuestionThis is fantastic code but i need help!!! Pinmemberjasinthebasin23:59 2 Aug '06  
AnswerRe: This is fantastic code but i need help!!! PinmemberFaisal Haroon1:09 16 Aug '06  
Questionthis is an amazing code [modified] Pinmembercnean6:18 27 Jun '06  
QuestionRe: this is an amazing code PinmemberFaisal Haroon6:19 5 Jul '06  
GeneralReturn Variable if Disabled Pinmembericeman22108:53 19 Jun '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 10 Oct 2003
Article Copyright 2003 by Faisal Haroon
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid