• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

How to authenticate against Active Directory with WinNT:// provider?

Hi, I got the following code from microsoft website to authenticate against AD but this code only valid with LDAP and not with WinNT:// because it uses DirectorySearcher which is not supported by WinNT://
How can I modify it to autheiticate agains AD with WinNT:// ?
Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean
 
            Dim domainAndUsername As String = domain & "\" & username
            Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)
 
            Try
                'Bind to the native AdsObject to force authentication.			
                Dim obj As Object = entry.NativeObject
                Dim search As DirectorySearcher = New DirectorySearcher(entry)
 
                search.Filter = "(SAMAccountName=" & username & ")"
                search.PropertiesToLoad.Add("cn")
                Dim result As SearchResult = search.FindOne()
 
                If (result Is Nothing) Then
                    Return False
                End If
 
                'Update the new path to the user in the directory.
                _path = result.Path
                _filterAttribute = CType(result.Properties("cn")(0), String)
 
            Catch ex As Exception
                Throw New Exception("Error authenticating user. " & ex.Message)
            End Try
 
            Return True
        End Function

Open in new window

0
Abdu_Allah
Asked:
Abdu_Allah
  • 3
  • 2
1 Solution
 
qf3l3kCommented:
Not sure if this is what you are looking for:

Set objComputer = GetObject("WinNT://MyDomain/TestComputer,computer")
Set objGroup = GetObject("WinNT://MyComputer/TestGroup,group")
Set objUser = GetObject("WinNT://MyDC/MyDomain/JohnDoe,user")

Above 3 examples how to bind different type of object.

Is that method you looking for or you have more specific need?
0
 
Abdu_AllahAuthor Commented:
>Is that method you looking for or you have more specific need?
No that is not what I want , all what I want  is to verify that the user is exist and if so check if the password he provided match the one that is stored in the AD (Authentication process.)
0
 
qf3l3kCommented:
Maybe this piece of code will work for you then:

On Error Resume Next

Set dso = GetObject("WinNT:")
Set lobjUser = dso.OpenDSObject("WinNT://DOMAIN", "DOMAIN\username", "abc123", 1)

WScript.Echo Err.Number

If Err.Number = 0 Then
      AuthenticateUser = 0
      WScript.Echo "Authenticated"
      
      Else

      AuthenticateUser = 1 'not authenticated
      WScript.Echo "Not Authenticated"
      
End If


Hope that will be a bit of a help?
0
 
qf3l3kCommented:
In fact one more thing. I did test it in VBscript, that's why code is minimal.
0
 
Abdu_AllahAuthor Commented:
This is a VB 6 not .NET!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now