新建用户可以';无法验证
本文关键字:验证 用户 新建 | 更新日期: 2023-09-27 17:59:23
using(PrincipalContext cntx = new PrincipalContext(
ContextType.Domain, "blah.corp.net:389", "OU=customers,OU=web,CN=blah,CN=corp,CN=net",
ContextOptions.Negotiate, "Domin'Admin", "{Password}")){
string password = "PPaass00!!";
UserPrincipal p = new UserPrincipal(cntx);
p.SamAccountName = "GuestUser";
p.PasswordNeverExpires = true;
p.Enabled = true;
p.SetPassword(password);
p.Save();
bool b = cntx.ValidateCredentials("GuestUser", password); //where b always false
}
我不明白为什么b总是假的。有人能帮忙吗?
虽然我不知道你的问题的答案,但你试过这种方法吗?
PrincipalContext cntx = new PrincipalContext(ContextType.Domain,
"blah.corp.net:389",
"OU=customers,OU=web,CN=blah,CN=corp,CN=net",ContextOptions.Negotiate,
"Domin'GuestUser", password)
在它周围放一个try/catch,看看它是否在连接时抛出异常。