How do I authenticate a userID/PW against AD.

Discussion in 'Active Directory' started by PaulS, Jun 21, 2005.

  1. PaulS

    PaulS Guest

    I'm sure this question has been asked and answered many times before, but I
    can't find any information on this subject. I want to authenticate a
    userID/PW against AD using an ldap bind and every example I can find does so
    using the comman name or display name format. In other words, the ldap bind
    examples always set CN=John Doe,CN=Users . . . I can get my code to work
    using this method, but I don't have the display name. I want to authenticate
    the userID (jdoe). I can do this using a Sun directory server, but I can't
    get it to work with AD. Can some one point me to an example or otherwise
    explain how to do this to this old block head.


    PaulS, Jun 21, 2005
    1. Advertisements

  2. Hi Paul,

    Here's some code which uses defined credentials to access AD, you can
    use the same thing to authenticate a user (bind to rootdse for example,
    and have some error-handling to verify the user was authenticated).
    Note: the code should give you an example, however you will need to
    adjust it to your environment and might need to fix errors - I've just
    typed down some parts without testing it.

    const ADS_SERVER_BIND = 512

    server = "" ' No specific server in this case
    Objectdn = "RootDSE"
    user = "company\user1"
    password = "My Secret Password!"

    If (server <> "") Then
    If (right(server,1) = "/") Then
    conserver = server
    conserver = server & "/"
    End If
    conserver = ""
    End If

    ' Binding with different credentials
    Set dso = GetObject("LDAP:")

    On Error resume next

    Set obj = dso_OpenDSObject( _
    "LDAP://" & conserver & objectdn, _
    user, _
    password, _

    If err.number <> 0 then
    Wscript.echo "Bind was not sucessfull:"
    Wscript.echo err.number & ": " & err.description
    Wscript.Echo "Bind was sucessfull, " & user & " was authenticated"
    End if

    On error goto 0

    Gruesse - Sincerely,

    Ulf B. Simon-Weidner

    MVP-Book "Windows XP - Die Expertentipps":
    Ulf B. Simon-Weidner [MVP], Jun 22, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.