我如何可以验证用户名和密码对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? :-)
阅读所有关于它的:
在.NET Framework管理目录安全主体3.5 上System.DirectoryServices.AccountManagement MSDN文档 Managing Directory Security Principals in the .NET Framework 3.5 MSDN docs on System.DirectoryServices.AccountManagement更新:
作为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!)
上一篇:如何录音并保存为MP3格式的AS3(的Adobe Air2.5)?保存为、格式、Adobe
下一篇:我可以得到从Asp.Net一个DirectorySearcher从1000多个记录?多个、可以得到、Asp、Net