验证用户名和密码对Active Directory? [英] Validate a username and password against Active Directory?

查看:427
本文介绍了验证用户名和密码对Active Directory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以验证用户名和密码对Active Directory?我只是想检查用户名和密码是正确的。

How can I validate a username and password against Active Directory? I simply want to check if a username and password are correct.

推荐答案

如果你工作在.NET 3.5或更高版本,可以使用 System.DirectoryServices.AccountManagement 命名空间轻松地验证您的凭据:

If you work on .NET 3.5 or newer, you can use the System.DirectoryServices.AccountManagement namespace and easily verify your credentials:

// create a "principal context" - e.g. your domain (could be machine, too)
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOURDOMAIN"))
{
    // validate the credentials
    bool isValid = pc.ValidateCredentials("myuser", "mypassword");
}

这很简单,它是可靠的,它是100%C#托管code对你的最终 - 你还能要求什么呢? : - )

It's simple, it's reliable, it's 100% C# managed code on your end - what more can you ask for? :-)

阅读所有关于它的:

  • Managing Directory Security Principals in the .NET Framework 3.5
  • MSDN docs on System.DirectoryServices.AccountManagement

更新:

作为<一个概述href="http://stackoverflow.com/questions/8949501/why-does-active-directory-validate-last-password">this其他等问题(和它的答案),有一个问题,这个调用可能返回为用户的旧密码。要知道这种行为,不要太惊讶,如果发生这种情况:-)(感谢@MikeGledhill指出这点!)

As outlined in this other SO question (and its answers), there is an issue with this call possibly returning True for old passwords of a user. Just be aware of this behavior and don't be too surprised if this happens :-) (thanks to @MikeGledhill for pointing this out!)

这篇关于验证用户名和密码对Active Directory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆