使用 System.DirectoryServices 验证域用户

2023-11-27

给定域用户的用户名和密码,以编程方式验证该用户的最佳方法是什么?


.NET 3.5 似乎添加了一个新的命名空间来处理此问题 - System.DirectoryServices.AccountManagement。代码示例如下:

Private Function ValidateExternalUser(ByVal username As String, ByVal password As String) As Boolean
    Using context As PrincipalContext = New PrincipalContext(ContextType.Domain, _defaultDomain)
        Return context.ValidateCredentials(username, password, ContextOptions.Negotiate)
    End Using
End Function

命名空间似乎还提供了很多操作域帐户的方法(更改密码、使密码过期等)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 System.DirectoryServices 验证域用户 的相关文章

随机推荐