public static bool CheckADAccountNew(this CuBzDACCommoncs bzCommon, string account, string password)
{
ContextType ctxType = ContextType.Domain;
try
{
string server = "xx.xx.com";
//account=用户名,password=密码
using (var ctx = new PrincipalContext(ctxType, server, account, password))
{
using (var findByIdentity = UserPrincipal.FindByIdentity(ctx, account))
{
if (findByIdentity == null)
{
return false;
}
if (ctx.ValidateCredentials(account, password))
{
return true;
}
else
{
return false;
}
}
}
}
catch (Exception ex)
{
LogHelper.Loger.logException("", "", ex);
}
return false;
}
c# 域用户登录
![](https://img-home.csdnimg.cn/images/20240711042549.png)