我在Visual Basic(VB6)中有一个应用程序,我试图通过Active Directory对用户进行身份验证。验证VB6中的Active Directory用户
是否可以验证用户名和密码?
我正在使用下面的代码来验证,但我不知道如何添加密码也验证用户。
Public Function FindUserGroupInfo(LoginName As String, GroupName As String) As Boolean
' Searches for a user within a specified group in Active Directory.
' Returns TRUE if the user is found in the specified group.
' Returns FALSE if the user is not found in the group.
' LDAP Search Query Properties
Dim conn As New ADODB.Connection ' ADO Connection
Dim rs As ADODB.Recordset ' ADO Recordset
Dim oRoot As IADs
Dim oDomain As IADs
Dim sBase As String
Dim sFilter As String
Dim sDomain As String
Dim sAttribs As String
Dim sDepth As String
Dim sQuery As String
Dim sAns As String
' Search Results
Dim user As IADsUser
Dim group As Variant
Dim usergroup As String
Dim userGroupFound As Boolean
On Error GoTo ErrHandler:
userGroupFound = False
'Set root to LDAP/ADO.
'LDAP://skb_ii.com/DC=skb_ii,DC=com
Set oRoot = GetObject("LDAP://rootDSE")
'Create the Default Domain for the LDAP Search Query
sDomain = oRoot.Get("defaultNamingContext")
Set oDomain = GetObject("LDAP://" & sDomain)
sBase = "<" & oDomain.ADsPath & ">"
' Set the LDAP Search Query properties
sFilter = "(&(objectCategory=person)(objectClass=user)(name=" & LoginName & "))"
sAttribs = "adsPath"
sDepth = "subTree"
sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
' Open the ADO connection and execute the LDAP Search query
conn.Open "Data Source=Active Directory Provider;Provider=ADsDSOObject"
Set rs = conn.Execute(sQuery) ' Store the query results in recordset
' Display the user details
If Not rs.EOF Then
Set user = GetObject(rs("adsPath"))
' Display the groups memberships
For Each group In user.Groups
usergroup = group.Name
If (InStr(usergroup, GroupName) > 0) Then
FindUserGroupInfo = True
Exit Function
End If
Next
End If
FindUserGroupInfo = userGroupFound
ErrHandler:
On Error Resume Next
If Not rs Is Nothing Then
If rs.State <> 0 Then rs.Close
Set rs = Nothing
End If
If Not conn Is Nothing Then
If conn.State <> 0 Then conn.Close
Set conn = Nothing
End If
Set oRoot = Nothing
Set oDomain = Nothing
End Function
它与其他任何语言一样GE。要么调用适当的Win32 API函数,要么进行AD查询。你甚至可以检查Technet的Scriptomatic是否已准备好制作'vbs'脚本。你有没有尝试过这些东西? –
谢谢,请参阅我编辑的问题。 – Roshe
顺便说一句,**为什么**你想验证用户?登录的域用户已经通过AD验证,您的应用程序知道它以及您的应用程序试图执行的任何操作使用该用户的凭据。你想模仿另一个域用户吗? –