1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Public Function IsAuthenticated(ByVal username As String, ByVal pwd As String) As Boolean
Dim domainAndUserName As String = "XXXX.XXXXX" & "\" & username
Dim entry As New DirectoryEntry(_path, domainAndUserName, pwd)
Try
Dim obj As Object = entry.NativeObject
Dim search1 As New DirectorySearcher(entry)
Dim result1 As SearchResult = Nothing
With search1
.Filter = "(userPrincipalName=" & username & "@XXXX.XXXXX)"
.PropertiesToLoad.Add("cn")
result1 = .FindOne()
End With
If IsNothing(result1) Then
Dim search2 As New DirectorySearcher(entry)
Dim result2 As SearchResult = Nothing
With search2
.Filter = "(SAMAccountName=" & username & ")"
.PropertiesToLoad.Add("cn")
result2 = .FindOne()
End With
If IsNothing(result2) Then
Return False
Else
_path = result2.Path
_filterAttribute = Convert.ToString(result2.Properties("cn")(0))
GetUserData(username)
End If
Else
_path = result1.Path
_filterAttribute = Convert.ToString(result1.Properties("cn")(0))
GetUserData(username)
End If
Catch ex As Exception
Return False
End Try
Return True
End Function |
Partager