Solved

How to get more values from LDAP with Classic ASP

Posted on 2013-02-06
3
1,176 Views
Last Modified: 2013-02-06
I have the function below that works, but I need it to give me back the values for sn, givenname, and mail from the LDAP but I cannot figure out how to make it work. Any help is appreciated.

With the following code:

function AuthenticateUser(UserName, Password, Domain)
dim strUser

AuthenticateUser = false

strUser = UserName
strPassword = Password

strQuery = "SELECT cn,sn,givenname,mail FROM 'LDAP://" & strDomain & "' 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

set oRS = cmd.Execute

if oRS.bof or oRS.eof then
  AuthenticateUser = false
else
  AuthenticateUser = true
end if

oConn.close
set oRS = nothing
set oConn = nothing

end function
0
Comment
Question by:Donnie Walker
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Tony Massa earned 500 total points
ID: 38861753
Are you trying to authenticate as some other account, or are you searching for information (attributes) for just the one "strUser" person?

http://blogs.technet.com/b/heyscriptingguy/archive/2005/12/09/how-can-i-use-alternate-credentials-when-searching-active-directory.aspx
0
 

Author Comment

by:Donnie Walker
ID: 38861775
I have the user logging in with HTTP Basic Authentication and I then pass that to the function above.

So, they are logging in.

I just want to get their first, last name and email so I can use it else where.

I got the function some place and now I'm trying to figure out how to grab that data.
0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 38861954
Maybe this link will give you some ideas
http://answers.google.com/answers/threadview?id=365115

You can grant them access to the site based on their Windows log-in
simply by unenabling Anonymous access and enabling Integrated Windows
authentication in the IIS console -> Anonymous access and
authentication control -> Edit... dialogue.

Once authenticated with Integrated Windows, you can get their username
through Request.ServerVariables("LOGON_USER").

Then use ADSI (Active Directory Services Interface). Pretty easy in
classic ASP and VBScript. Then you can get a user object through ADSI
based on the logged in username and the domain name
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question