There isn't really a need for the Success variable, you could just do this (I would also recommend using the Secure binding as I have done in the code below)
vb Code:
Private Function ValidateActiveDirectoryLogin(ByVal domain As String, ByVal username As String, ByVal userPassword As String) As Boolean Using rootEntry As New System.DirectoryServices.DirectoryEntry("LDAP://" & domain, username, userPassword, DirectoryServices.AuthenticationTypes.Secure) Using adSearcher As New System.DirectoryServices.DirectorySearcher(rootEntry) adSearcher.SearchScope = DirectoryServices.SearchScope.OneLevel Try Dim searchResults As System.DirectoryServices.SearchResult = adSearcher.FindOne Return Not searchResults Is Nothing Catch Return False End Try End Using End Using End Function
Again though, anyone using .NET 3.5 or 4.0 should probably just use the built in methods in the Sytem.DirectoryServices.AccountManagement namespace to do this.





Reply With Quote