| re: Asp Ldap authentication and redirection based on OU
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
|