Solved

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

Posted on 2009-05-09
5
638 Views
Last Modified: 2012-05-06
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
Comment
Question by:Abdu_Allah
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:qf3l3k
ID: 24349554
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
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 24353104
>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
 
LVL 5

Accepted Solution

by:
qf3l3k earned 500 total points
ID: 24354034
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
 
LVL 5

Expert Comment

by:qf3l3k
ID: 24354052
In fact one more thing. I did test it in VBscript, that's why code is minimal.
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 24354482
This is a VB 6 not .NET!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 39
Host asp.net pages 5 25
block folder inheritance 4 33
SQL Exceptions 3 36
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now