Hi, I'm trying to connect to the active directory using asp. I'm having problems with logging in, what happens is the username accepted is not the user logon name but the displayname is accpeted heres the code:

Dim oRootDSE, oCon, oCmd, oRecordSet,oRecordset1
Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
Dim aDescription, aMember, iCount,aUser,oCmd1,oUsers,oUsersADsPath

Set oRootDSE         = GetObject("LDAP://192.168.128.100/RootDSE")
sDomainADsPath        = "LDAP://192.168.128.100/" & "cn=ichigo kurosaki;cn=users;" & oRootDSE.Get("defaultNamingContext")   ''      "cn=users;" &
Set oRootDSE         = Nothing             


Set oCon         = Server.CreateObject("ADODB.Connection")

sUser            =         "ichigo kurosaki"      '   "0034"   my logon name is 0034 and the display and full name is ichigo kurosaki
sPassword        =  "abc123@"   '   
oCon.Provider         = "ADsDSOObject"

oCon.Open "ADProvider", sUser, sPassword

Set oCmd        = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

sProperties        = "samaccountname,name,ADsPath,cn"
sGroup            = "*"

oCmd.CommandText    = "<" & sDomainADsPath & ">;(&(objectCategory=user)(samaccountname=" & "0034"& "));" & sProperties ''   & ";subtree"
oCmd.Properties("Page Size") = 100

when i use 0034 the page displays a permission denied error. is there a way to login with the logon name? and isnt the logon name supposed to be used for logging in and not the display name?

THANKS IN ADVANCE :cheesy:

Hi, I'm trying to connect to the active directory using asp. I'm having problems with logging in, what happens is the username accepted is not the user logon name but the displayname is accpeted heres the code:

Dim oRootDSE, oCon, oCmd, oRecordSet,oRecordset1
Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
Dim aDescription, aMember, iCount,aUser,oCmd1,oUsers,oUsersADsPath

Set oRootDSE         = GetObject("LDAP://192.168.128.100/RootDSE")
sDomainADsPath        = "LDAP://192.168.128.100/" & "cn=ichigo kurosaki;cn=users;" & oRootDSE.Get("defaultNamingContext")   ''      "cn=users;" &
Set oRootDSE         = Nothing             


Set oCon         = Server.CreateObject("ADODB.Connection")

sUser            =         "ichigo kurosaki"      '   "0034"   my logon name is 0034 and the display and full name is ichigo kurosaki
sPassword        =  "abc123@"   '   
oCon.Provider         = "ADsDSOObject"

oCon.Open "ADProvider", sUser, sPassword

Set oCmd        = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

sProperties        = "samaccountname,name,ADsPath,cn"
sGroup            = "*"

oCmd.CommandText    = "<" & sDomainADsPath & ">;(&(objectCategory=user)(samaccountname=" & "0034"& "));" & sProperties ''   & ";subtree"
oCmd.Properties("Page Size") = 100

when i use 0034 the page displays a permission denied error. is there a way to login with the logon name? and isnt the logon name supposed to be used for logging in and not the display name?

THANKS IN ADVANCE :cheesy:

function AuthenticateUser(UserName, Password, Domain)


' assume failure

AuthenticateUser = false

strUser = UserName

strPassword = Password

strQuery="Select cn from '" & domain & "' where objectClass='*' "

set oConn = server.CreateObject("ADODB.Connection")

oConn.Provider = "ADsDSOOBJECT"

oConn.Properties("User ID") = strUser

oConn.Properties("Password") = strPassword

oConn.Properties("Encrypt Password") = true

oConn.open "DS Query", strUser, strPassword

set cmd = server.CreateObject("ADODB.Command")

set cmd.ActiveConnection = oConn

cmd.CommandText = strQuery

'on error resume next

set oRS = cmd.Execute

if err<>0 then DisplayErrors oConn.Errors

if oRS.bof or oRS.eof then

AuthenticateUser = false

else

AuthenticateUser = true

end if

set oRS = nothing

set oConn = nothing

' response.write("Success=" & AuthenticateUser)

' response.end

end function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.