473,411 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Asp Ldap authentication and redirection based on OU

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
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5. <title>Intranet</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <%
  11. dim submit
  12. dim UserName
  13. dim Password
  14.  
  15.  
  16. UserName = "mydoamin/username"
  17. Password = ""
  18. Domain = "mydomain"
  19. submit = request.form("submit")
  20.  
  21. if submit = "Authenticate" then
  22. UserName = request.form("UserName")
  23. Password = request.form("Password")
  24. Domain = request.form("Domain")
  25. result = AuthenticateUser(UserName, Password, Domain)
  26. if result then
  27. Response.Redirect("basic page")
  28. else
  29. response.write "<h3>Authentication Failed!</h3>"
  30. end if
  31. end if
  32.  
  33. response.write "<hr><form method=post>"
  34. response.write "<table>"
  35. response.write "<tr>"
  36. response.write "<td><b>Username:&nbsp;</b></td><td><input type=""text"" name=""UserName"" value=""" & UserName & """>"
  37. response.write "</tr>"
  38. response.write "<tr>"
  39. response.write "<td><b>Password:&nbsp;</b></td><td><input type=""password"" name=""Password"" value=""" & Password & """ </td>"
  40. response.write "</tr>"
  41. response.write "<tr>"
  42. response.write "<td><b>AD Domain:&nbsp;</b></td><td><input type=""text"" name=""Domain"" value=""" & Domain & """ <br></td>"
  43. response.write "</tr>"
  44. response.write "<tr>"
  45. response.write "<td>&nbsp;</td><td><input name=""submit"" type=""submit"" value=""Authenticate""></td>"
  46. response.write "</tr>"
  47. response.write "</table>"
  48. response.write "</form>"
  49. response.end
  50.  
  51. function AuthenticateUser(UserName, Password, Domain)
  52. dim strUser
  53. ' assume failure
  54. AuthenticateUser = false
  55.  
  56. strUser = UserName
  57. strPassword = Password
  58.  
  59.  
  60. strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
  61. set oConn = server.CreateObject("ADODB.Connection")
  62. oConn.Provider = "ADsDSOOBJECT"
  63. oConn.Properties("User ID") = strUser
  64. oConn.Properties("Password") = strPassword
  65. oConn.Properties("Encrypt Password") = true
  66. oConn.open "DS Query", strUser, strPassword
  67.  
  68. set cmd = server.CreateObject("ADODB.Command")
  69. set cmd.ActiveConnection = oConn
  70. cmd.CommandText = strQuery
  71. on error resume next
  72. set oRS = cmd.Execute
  73. if oRS.bof or oRS.eof then
  74. AuthenticateUser = false
  75. else
  76. AuthenticateUser = true
  77. end if
  78. set oRS = nothing
  79. set oConn = nothing
  80.  
  81. end function
  82.  
  83. %>
  84.  
  85. </body>
  86. </html>
Oct 25 '09 #1
3 5787
jhardman
3,406 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. response.write "<table><tr>" & vbNewLine
  2. dim x
  3. for each x in oRS.fields
  4.    response.write "<td>" & x.name & "</td>" & vbNewLine
  5. next
  6. response.write "</tr><tr>" & vbNewLine
  7. do until oRS.eof
  8.    for each x in oRS.fields
  9.       response.write "<td>" & x.value & "</td>" & vbNewLine
  10.    next
  11.    response.write "</tr><tr>"
  12.  
  13.    oRS.movenext
  14. loop
  15. response.write "</tr></table>" & vbNewLine
Let me know if this helps.

Jared
Oct 28 '09 #2
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:&nbsp;</b></td><td><input type=""text"" name=""UserName"" value=""" & UserName & """>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>Password:&nbsp;</b></td><td><input type=""password"" name=""Password"" value=""" & Password & """ </td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>AD Domain:&nbsp;</b></td><td><input type=""text"" name=""Domain"" value=""" & Domain & """ <br></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td>&nbsp;</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
Oct 29 '09 #3
jhardman
3,406 Expert 2GB
@Genius79
The oconn properties are just putting things in the database connection string, definitely not the place to mention the organizational unit. Try this:
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT * FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
  2. set oConn = server.CreateObject("ADODB.Connection")
  3. oConn.Provider = "ADsDSOOBJECT"
  4. oConn.Properties("User ID") = strUser
  5. oConn.Properties("Password") = strPassword
  6. oConn.Properties("Encrypt Password") = true
  7. oConn.open 
  8. set oRS = server.createobject("adodb.recordset")
  9. oRS.open strQuery, oConn
  10.  
  11. response.write "<table><tr>"
  12. for each x in oRS.fields
  13.    response.write "<th>" & x.name & "</th>" & vbNewLine
  14. next
  15. response.write "</tr>"
  16.  
  17. do until oRS.eof
  18.    response.write "<tr>" & vbNewLine
  19.  
  20.    for each x in oRS.fields
  21.       response.write "<td>" & x.value & "</td>" & vbNewLine
  22.    next
  23.  
  24.    response.write "</tr>"
  25.    oRS.movenext
  26. loop
  27. response.write "</table>"
  28.  
Nov 3 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
3
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...
3
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 ...
0
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: ...
6
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...
2
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.
2
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...
3
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...
1
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.