468,272 Members | 1,980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Ldap search within active directory for authentication via ASP

3
Hi, I hope you guys can help me.

I need to build a form that request username and password on ASP not ASP.net (sorry to clarify but i got some responses in other forums in .net)

This form will send an LDAP query into the active directory located on a different server and it will check for existing users.

If the users exist they will be redirected to a new page. if not they will be prompt to try again for username and password.


What is happening I am gett authentication failed all the time. I know i am a user but I dont know why I am not being redirected to the page i need.

could it be that the server is using another way of saving the users other than LDAP or Active directory?

To be more specific. People are being added to an Xchange server for email purposes. This creates a username (email) and a password. Giving them access to a webmail.

how can i compare this list of users using this code.

the form i am working with is this

Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim submit
  3. dim UserName
  4. dim Password
  5.  
  6. UserName = ""
  7. Password = ""
  8. Domain = "domain.com"
  9.  
  10. submit = request.form("submit")
  11.  
  12. if submit = "Authenticate" then
  13. UserName = request.form("UserName")
  14. Password = request.form("Password")
  15. Domain = request.form("Domain")
  16. result = AuthenticateUser(UserName, Password, Domain)
  17. if result then
  18. Response.Write("<script>window.open('../forms/default.asp','');</script>")
  19. else
  20. response.write "<h3>Authentication Failed!</h3>"
  21. end if
  22. end if
  23.  
  24. response.write "<hr><form method=post>"
  25. response.write "<table>"
  26. response.write "<tr>"
  27. response.write "<td><b>Username:&nbsp;</b></td><td><input type='text'"
  28. name="'UserName' value='' & UserName & '' size='30'></td>"
  29. response.write "</tr>"
  30. response.write "<tr>"
  31. response.write "<td><b>Password:&nbsp;</b></td><td><input type='password' name='Password' value='' & Password & '' size='30'></td>"
  32. response.write "</tr>"
  33. response.write "<tr>"
  34. response.write "<td><b>AD Domain:&nbsp;</b></td><td><input type='text' name='Domain' value='' & Domain & '' size='30'></td>"
  35. response.write "</tr>"
  36. response.write "<tr>"
  37. response.write "<td>&nbsp;</td><td><input name='submit' type='submit' value='Authenticate'></td>"
  38. response.write "</tr>"
  39. response.write "</table>"
  40. response.write "</form>"
  41. response.end
  42.  
  43. function AuthenticateUser(UserName, Password, Domain)
  44. dim strUser
  45. ' assume failure
  46. AuthenticateUser = false
  47.  
  48. strUser = UserName
  49. strPassword = Password
  50.  
  51. strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
  52. set oConn = server.CreateObject("ADODB.Connection")
  53. oConn.Provider = "ADsDSOOBJECT"
  54. oConn.Properties("User ID") = strUser
  55. oConn.Properties("Password") = strPassword
  56. oConn.Properties("Encrypt Password") = true
  57. oConn.open "DS Query", strUser, strPassword
  58.  
  59. set cmd = server.CreateObject("ADODB.Command")
  60. set cmd.ActiveConnection = oConn
  61. cmd.CommandText = strQuery
  62. on error resume next
  63. set oRS = cmd.Execute
  64. if oRS.bof or oRS.eof then
  65. AuthenticateUser = false
  66. else
  67. AuthenticateUser = true
  68.  
  69. end if
  70. set oRS = nothing
  71. set oConn = nothing
  72.  
  73. end function
  74.  
  75. %>
Oct 2 '09 #1
5 5158
CroCrew
564 Expert 512MB
Hello wak0,

Question: Is the web server in the domain? Or is it a standalone web server?

CroCrew~
Oct 9 '09 #2
wak0
3
stand alone. Thanks for replying
Oct 9 '09 #3
CroCrew
564 Expert 512MB
Hello wak0,

Since you are doing a server-less bind to Active Directory, ADSI tries to pick up the domain to use based on the current security context of the executing thread. In ASP, impersonation is always used.

Try to add “/rootDSE” after your domain name:

LDAP://domain.com/rootDSE

In general, if the web server was within the domain, I'd suggest using Windows authentication instead. Windows Authentication allows you to avoid this mess and will give you better scalability.

Consider going down this path if Windows Authentication is absolutely not a possibility:

Expand|Select|Wrap|Line Numbers
  1. Set objDSObj = GetObject("LDAP:")
  2. Set objAuth = objDSObj.OpenDSObject("LDAP://domain.com/rootDSE",
  3. strDomainUser, strPassword, 1)
  4.  

Hope that it helps,
CroCrew~
Oct 9 '09 #4
wak0
3
that is what i found out. thanks for the tip. will implement and check back
Oct 9 '09 #5
CroCrew
564 Expert 512MB
Let us know if it works out for ya. It could help the next person.

Good luck,
CroCrew~
Oct 9 '09 #6

Post your reply

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

Similar topics

2 posts views Thread by Victor Lokhmatov | last post: by
5 posts views Thread by dmcconkey | last post: by
7 posts views Thread by Amar | last post: by
1 post views Thread by Andrew | last post: by
5 posts views Thread by Ganesh Ramamurthy | last post: by
1 post views Thread by Serge | last post: by
2 posts views Thread by duncan beaumont | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.