Public Function IsAuthenticated(ByVal username As String, ByVal pwd As String) As Boolean
Dim entry As DirectoryEntry = New DirectoryEntry(_path, username, pwd) entry.AuthenticationType = AuthenticationTypes.Secure entry.Path = _path
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") search.PropertiesToLoad.Add("givenName")
Dim result As SearchResult = search.FindOne() Dim info As DirectoryEntry = result.GetDirectoryEntry ' Label4.Text=CType(info.Properties("displayName").?? String.Empty, String)
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) '_filterAttribute = CType(result.Properties("givenName")(1), String)
Catch ex As Exception Throw New Exception("Error authenticating user. " & ex.Message) End Try ' WriteLine(_filterAttribute)
Return True
End Function
|
No responses found. Be the first to respond and make money from revenue sharing program.
|