Hi I'm trying to do an ASP authentication using Ldap and would like to have the users directed to pages based on the Organizational Unit. My ASP knowledge is pretty basic but would really like to get this sorted to complete the intranet.
Thx I've found the following code on this website and manage to get the username and password authentication working just need to figure out how to redirect to the OU.
Thanks -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
-
<html>
-
<head>
-
<title>Intranet</title>
-
</head>
-
-
<body>
-
-
<%
-
dim submit
-
dim UserName
-
dim Password
-
-
-
UserName = "mydoamin/username"
-
Password = ""
-
Domain = "mydomain"
-
submit = request.form("submit")
-
-
if submit = "Authenticate" then
-
UserName = request.form("UserName")
-
Password = request.form("Password")
-
Domain = request.form("Domain")
-
result = AuthenticateUser(UserName, Password, Domain)
-
if result then
-
Response.Redirect("basic page")
-
else
-
response.write "<h3>Authentication Failed!</h3>"
-
end if
-
end if
-
-
response.write "<hr><form method=post>"
-
response.write "<table>"
-
response.write "<tr>"
-
response.write "<td><b>Username: </b></td><td><input type=""text"" name=""UserName"" value=""" & UserName & """>"
-
response.write "</tr>"
-
response.write "<tr>"
-
response.write "<td><b>Password: </b></td><td><input type=""password"" name=""Password"" value=""" & Password & """ </td>"
-
response.write "</tr>"
-
response.write "<tr>"
-
response.write "<td><b>AD Domain: </b></td><td><input type=""text"" name=""Domain"" value=""" & Domain & """ <br></td>"
-
response.write "</tr>"
-
response.write "<tr>"
-
response.write "<td> </td><td><input name=""submit"" type=""submit"" value=""Authenticate""></td>"
-
response.write "</tr>"
-
response.write "</table>"
-
response.write "</form>"
-
response.end
-
-
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
-
-
%>
-
-
</body>
-
</html>
3 5787
OK, your query is only pulling up one field (cn) from LDAP. You will need to see what other fields are available (do "Select * ...", the * will pull up every field you have available) whether there is a field you can use. I've never tried it with LDAP, but this code should work: - response.write "<table><tr>" & vbNewLine
-
dim x
-
for each x in oRS.fields
-
response.write "<td>" & x.name & "</td>" & vbNewLine
-
next
-
response.write "</tr><tr>" & vbNewLine
-
do until oRS.eof
-
for each x in oRS.fields
-
response.write "<td>" & x.value & "</td>" & vbNewLine
-
next
-
response.write "</tr><tr>"
-
-
oRS.movenext
-
loop
-
response.write "</tr></table>" & vbNewLine
Let me know if this helps.
Jared
Hey Jared
Thanks for the assist. I've changed the "cn" to "*" and tried to pull the organizational Units from the Ldap but still no joy. I'm now seeing the following error when submitted " Error Type:
ADODB.Connection (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal." in the highlighted line.
Attaching modified code
<%
dim submit
dim UserName
dim Password
UserName = ""
Password = ""
Domain = "mydomain"
submit = request.form("submit")
if submit = "Authenticate" then
UserName = request.form("UserName")
Password = request.form("Password")
Domain = request.form("Domain")
result = AuthenticateUser(UserName, Password, Domain, strOU)
if result then
Response.Redirect("http://localhost/intranet/"& strOU &".html")
else
response.write "<h3>Authentication Failed!</h3>"
end if
end if
response.write "<hr><form method=post>"
response.write "<table>"
response.write "<tr>"
response.write "<td><b>Username: </b></td><td><input type=""text"" name=""UserName"" value=""" & UserName & """>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>Password: </b></td><td><input type=""password"" name=""Password"" value=""" & Password & """ </td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>AD Domain: </b></td><td><input type=""text"" name=""Domain"" value=""" & Domain & """ <br></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td> </td><td><input name=""submit"" type=""submit"" value=""Authenticate""></td>"
response.write "</tr>"
response.write "</table>"
response.write "</form>"
response.end
function AuthenticateUser(UserName, Password, strOU, Domain)
dim strUser
' assume failure
AuthenticateUser = false
strUser = UserName
strPassword = Password
StrOU = OU
strQuery = "SELECT * 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("Organizational Unit") = strOU
oConn.Properties("Encrypt Password") = true
oConn.open "DS Query", strUser, strPassword, strOU
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
%>
Maybe you can tell me where I've gone wrong.
Thank for the help
@Genius79
The oconn properties are just putting things in the database connection string, definitely not the place to mention the organizational unit. Try this: - strQuery = "SELECT * 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
-
set oRS = server.createobject("adodb.recordset")
-
oRS.open strQuery, oConn
-
-
response.write "<table><tr>"
-
for each x in oRS.fields
-
response.write "<th>" & x.name & "</th>" & vbNewLine
-
next
-
response.write "</tr>"
-
-
do until oRS.eof
-
response.write "<tr>" & vbNewLine
-
-
for each x in oRS.fields
-
response.write "<td>" & x.value & "</td>" & vbNewLine
-
next
-
-
response.write "</tr>"
-
oRS.movenext
-
loop
-
response.write "</table>"
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dmcconkey |
last post by:
Hi folks,
I've been searching for a while and haven't found my specific question
anywhere else. If this has already been asked, please accept my
appologies and point me to the appropriate...
|
by: jeremy |
last post by:
Hello.
I have an asp.net application that resides on a non-DC / BDC Sharepoint
Server (although it is logged into the domain). The application will perform
lookups based on the current user...
|
by: mrwoopey |
last post by:
Hi,
I am using the example "Authenticate against the Active Directory by
Using Forms Authentication and Visual Basic .NET":
http://support.microsoft.com/default.aspx?scid=KB;EN-US;326340
...
|
by: Luis Esteban Valencia |
last post by:
I've never worked with LDAP before, and I'm having issues connecting to our
AD for user authentication. I am trying to use the code found at:
...
|
by: Notgiven |
last post by:
I am considering a large project and they currently use LDAP on MS platform.
It would be moved to a LAMP platform. OpenLDAP is an option though I have
not used it before. I do feel fairly...
|
by: duncan beaumont |
last post by:
Hi,
- SQLserver 2000
- Yellowfin 2.4
- Windows 2003 server
I have been asked to investigate seting up LDAP authentication to
access our
Yellowfin reporting.
|
by: Anbu |
last post by:
Sorry for cross posting the query. But I need a resolution as early as
possible.
I have developed an application to authenticate the user based on LDAP
Search and authentication.
The Windows...
|
by: RJN |
last post by:
Hi
I've written a code that queries Windows LDAP server and works fine, but
the same doesn't work when querying Solaris LDAP server.
DirectoryEntry de = new...
|
by: jesbuddy07 |
last post by:
Hello,
I'm using IIS 5 and PHP 4.3.5.
I have an html page, page1, that resides at member.company.com server.
It contains a form asking a user to login. I then check the login by
connecting to...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |