Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LDAP authentication in ASP 3

Status
Not open for further replies.

TheUser5

Programmer
Dec 15, 2004
8
US
I have been strugging with this one.

I am trying to authenticate users against a LDAP server (Novell). By trial and error, I got following code to work but the issue is that I had to specify the whole ldapPath. i.e. I just want to search the whole LDAP tree for the given userid and authenticate.

Following code won't work if the user is in ou=external or ou=int8.

How can I make it generic so that it will search the whole tree? I tried following, but it didn't work:

ldapServer = "LDAP://servername:389/uid=#username#,dc=mydomain,dc=com"

Thanks in advance for any help.

-----------------

sub login3(userName, password)

Dim ldapServer, dso, lobjUser

On Error resume next

' Construct the FQDN

ldapServer = "LDAP://servername:389/uid=#username#,ou=int7,ou=internal,ou=people,c=us,cn=users,dc=mydomain,dc=com"

ldapServer = replace(ldapServer, "#username#", userName)

' Connect to the LDAP Directory

Set dso = GetObject("LDAP:")

'parse the username
userName = Mid(ldapserver, InStr(8, ldapserver, "/") + 1)
'Validate the User Name and Password
Set lobjUser = dso_OpenDSObject(ldapserver, userName, password, 0)

If Err.number <> 0 Then
Response.Write "<font color=red><STRONG>AUTHENTICATION FAILURE!</STRONG></font>"
Set lobjUser = nothing
Set dso = nothing
Else
Response.Write "<font color=green><STRONG>SUCCESS!</STRONG></font>"
end if

end sub
 
tsuji,

I doing some work for a company and I am not getting enough info. from them.

They have a Novell network and I asked them whether they're using Novell or Microsoft active directory and they haven't gotten back to me yet! But most likely, it's Novell.

Using LDAPExplorer, this is the structure of the directory:

dc=domain,dc=com
cn=users
uid=wpsadmin
c=us
ou=external
ou=internal
ou=int1
uid=11111111
uid=10000001
uid=10000002
.
.
ou=int2
ou=int3
c=canada
.
.
.
cn=groups
cn=ldapAdmins
cn=superadmin
cn=testuser
 
Thanks to the info tsuji provided I was able to get my project working properly.

Here is the end code I had that actually worked for enumerating that distinguishedName path.

Code:
userstring = WSHNetwork.UserName

On error Resume Next

Dim cont' As IADsContainer
Dim usr' As IADsUser

szUsername = "domainname\Administrator"
szPassword = "Password"


const ADS_SECURE_AUTHENTICATION=&h0001
const ADS_SERVER_BIND=&h0200
set ons=getobject("LDAP:")
set cont=ons.OpenDSObject( _
    "LDAP://OU=SBSUsers,OU=Users,OU=MyBusiness,DC=companName,DC=local", _
    szUsername, _
    szPassword, _
    ADS_SECURE_AUTHENTICATION or ADS_SERVER_BIND)

' Filter users.
cont.Filter = Array("user")

For Each usr In cont
	If lcase(usr.sAMAccountName) = lcase(userstring) Then
	  shortName = usr.sAMAccountName
	  ldpath = usr.distinguishedName
	End If
Next

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top