ASP form authentication and Active Directory

Author Message
rlawrason

  • Total Posts : 10
  • Scores: 2
  • Reward points : 0
  • Joined: 11/29/2006
  • Status: offline
ASP form authentication and Active Directory Thursday, September 25, 2008 3:03 AM (permalink)
0
I'm pretty new to ASP and I'm having a few issues.  Here is the code I'm working with:

If Trim(request.querystring("error")) <> ""  Then
 response.write "<p class=""detailtextbold""><font size=""2"" color=""maroon"">" & Trim(request.querystring("error")) & "</font></p>"
 End If
 
 if submit = "Log In" then
 UserName = request.form("UserName")
 Password = request.form("Password")
 Domain = "mydomain.com"
 result = AuthenticateUser(UserName, Password, Domain)
 if result then
 session("sess_var") = request.form("UserName")
 response.redirect("homepage.asp")
 else
 response.redirect("loginpage.asp?error=The%20account%20or%20password%20is%20invalid!%20%20Please%20try%20again.")
 end if
 end if
 
 function AuthenticateUser(UserName, Password, Domain)
 dim strUser
 ' assume failure
 AuthenticateUser = false
 
 strUser = UserName
 strPassword = Password
 
 strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
 set oConn = server.CreateObject("ADODB.Connection")
 oConn.Provider = "ADsDSOOBJECT"
 oConn.Properties("User ID") = strUser
 oConn.Properties("Password") = strPassword
 oConn.Properties("Encrypt Password") = true
 oConn.open "DS Query", strUser, strPassword
 
 set cmd = server.CreateObject("ADODB.Command")
 set cmd.ActiveConnection = oConn
 cmd.CommandText = strQuery
 on error resume next
 set oRS = cmd.Execute
 if oRS.bof or oRS.eof then
 AuthenticateUser = false
 else
 AuthenticateUser = true
 end if
 set oRS = nothing
 set oConn = nothing
 
 end function


As you can see, it is a pretty standard Active Directory authentication function that sets a session variable on success and an error redirection on fail.  The way in which I need to expand this code is to include an Active Directory Group membership challenge as well.

I'm pretty new at ASP, and to be honest I found most of this code snippet online to begin with and am re-using it for my purposes...anybody have any tips on how I can start to develop this more?

Thank you for your time.

 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9