基于Active Directory的用户验证
1. 基于AD的用户验证
public static bool IsUserValid (string UserName, string Password)
{
using (DirectoryEntry deUser = new DirectoryEntry(ADPath, UserName, Password, AuthenticationTypes.Secure))
{
try
{
// The NativeObject call on the DirectoryEntry object entry is an attempt to bind to the object in the directory.
// Since this call forces authentication, you will get an error if the user does not exist.
// If the user is a valid user in the domain, the call will succeed.
Object native = deUser.NativeObject;
return true;
}
catch
{
return false;
}
}
}
根据UserName/Password验证用户的合法性。需要注意的是:ADSI