I use asp classic to authenticate a user with LDAP. There are about 10 000 accounts in the LDAP and the check for authentication in asp is quite slow (15 seconds).
I used on the same server the LDP tool (from Microsoft) and everything (from connection, binding and search) is fast.
Here's my code, I tried 3 different options and I had same results :
Using SQL instructions :
Dim oConn: Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = Username
oConn.Properties("Password") = Password
oConn.Properties("Encrypt Password") = True
oConn.Open "DS Query", Username, Password
Dim Query: Query = "SELECT sAMAccountName FROM 'LDAP://ldap.mydomain.com/CN=" & Username & ",CN=Users' WHERE objectCategory = 'person' AND objectClass='user' AND SAMAccountName = '" & Username & "' "
Dim oCmd: Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = Query
Dim oRs: Set oRS = oCmd.Execute
If oRS.BOF Or oRS.EOF Then
' Authentication failed
Else
' Autentication passed
End If
...
Using LDAP instructions :
Dim oConn: Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = Username
oConn.Properties("Password") = Password
oConn.Properties("Encrypt Password") = True
oConn.Open "DS Query", Username, Password
Dim Query: Query = "<LDAP://ldap.mydomain.com>;(samAccountName=" & Username & ");samAccountName;subtree"
Dim oCmd: Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = Query
Dim oRs: Set oRS = oCmd.Execute
If oRS.BOF Or oRS.EOF Then
' Authentication failed
Else
' Autentication passed
End If
...
Using IADS objects :
Dim DSODomaine
Dim DSOContainer
On Error Resume Next
Set DSODomaine = GetObject("LDAP:")
Set DSOContainer = DSODomaine.OpenDSObject("LDAP://ldap.mydomain.com", Username, Password, ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
If Err.Number <> 0 Then
' Authentication failed
Else
' Autentication passed
End If
...
The 3 examples are all slow. What could I do to improve performance using asp classic ?