大网数据广告活动
域与目录服务

Authentication (ADSI)

· 52CE 我爱测

In ADSI, credentials that consist of a user name and password are used to provide or restrict access to objects in the directory service.

In ADSI, credentials that consist of a user name and password are used to provide or restrict access to objects in the directory service. The ADsGetObject function uses the credentials of the calling thread for authentication. The ADsOpenObject function and IADsOpenDSObject::OpenDSObject method can be used to specify credentials other than those of the calling thread. When an object is bound to with an authenticated user, the user is allowed access to the object as supported by the underlying directory service security requirements.

Note: The ADsOpenObject function and IADsOpenDSObject::OpenDSObject method should not be used to validate user credentials.

Important: Microsoft does not recommend the username and password flow because the application will be asking a user for their password directly, which is an insecure pattern. In most scenarios, there exist more secure flows that you can use.

The following code example shows how to use the OpenDSObject method to authenticate a user.

Dim MyNamespace As IADsOpenDSObject
Dim X
oUsername=GetUsernameFromSecureConfig() ' Get the username from a secure location (not shown)
oPassword=GetPasswordFromSecureConfig() ' Get the password from a secure location (not shown)

OnError GoTo CleanuUp
 
Set MyNamespace = GetObject("LDAP:")

' For authentication, pass a variable for the user name and password to be used for 
' authentication. For security reasons, it is recommended that you use the ADS_SECURE_AUTHENTICATION flag.
' 
Set X = MyNamespace.OpenDSObject(DN, oUserName, oPassword, ADS_SECURE_AUTHENTICATION)     

CleanUp:
    MsgBox ("An error has occurred.")
    Set MyNamespace = Nothing
    Set X = Nothing

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 08/20/2024
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。