Quote Originally Posted by jinx101 View Post
Just a note on the original code. If you use that code in any kind of loop the AD objects need to be disposed of because you'll leak lots of memory otherwise (speaking from personal experience):

Code:
        Public Shared Function ValidateLogin(ByVal domain As String, ByVal username As String, ByVal password As String) As Boolean
            Dim success As Boolean = False
            Dim entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & domain, username, password)
            Dim searcher As New System.DirectoryServices.DirectorySearcher(entry)
            searcher.SearchScope = DirectoryServices.SearchScope.OneLevel

            Try
                Dim results As System.DirectoryServices.SearchResult = searcher.FindOne
                success = Not (results Is Nothing)
            Catch ex As Exception
                success = False
            Finally
                entry.Close() : entry.Dispose()
                searcher.Dispose()
            End Try

            Return success

        End Function
That is a good point but one minor comment - you don't need to call Close and Dispose on the DirectoryEntry object because they both do pretty much exactly the same thing. The Close method just calls an internal method named Unbind (which frees up the resources that were used) and the Dispose method calls the same Unbind method but then also calls MyBase.Dispose. So I would just go with Dispose on its own and not bother with Close