Security 如何验证域凭据(来自本机代码)?
我想根据域控制器验证一组凭据。e、 g:Security 如何验证域凭据(来自本机代码)?,security,kerberos,ntlm,networkcredentials,Security,Kerberos,Ntlm,Networkcredentials,我想根据域控制器验证一组凭据。e、 g: Username: joel Password: splotchy Domain: STACKOVERFLOW 在.NET3.5及更新版本中 否则你就有麻烦了 按照Microsoft知识库文章中的代码,我得出了您所说的: 除此之外,该功能在以下情况下失败: (0x80090311) 该功能失败。无法联系任何机构进行身份验证。这可能是由于以下情况造成的: 验证方的域名不正确 域不可用 信任关系已失败 这将是一个有用的错误,但我可以使用以下方法验证
Username: joel
Password: splotchy
Domain: STACKOVERFLOW
在.NET3.5及更新版本中
否则你就有麻烦了
按照Microsoft知识库文章中的代码,我得出了您所说的:
除此之外,该功能在以下情况下失败:
(0x80090311)
该功能失败。无法联系任何机构进行身份验证。这可能是由于以下情况造成的:
- 验证方的域名不正确
- 域不可用
- 信任关系已失败
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
{
valid = context.ValidateCredentials(username, password);
}
当本机代码无法验证一组凭据时,会发生什么情况允许.NET验证一组凭据
更新:
登录用户
也会失败:
LogonUser("joel@stackoverflow.com", null, "splotchy",
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_WINNT50, out token);
与
更新两个:我尝试了首选的
协商
提供程序,以及Windows NT4传统的“NTLM”提供程序
我想这是为了解决与您发布的另一个问题相同的问题 我有点理解你现在想做什么。让我重述一下你在另一篇帖子上写的内容
Username Password Domain Machine on domain? Validate as
======== ======== ================= ================== ==============
iboyd pass1 . No Local account
iboyd pass1 (empty) No Local account
iboyd pass1 stackoverflow.com No Domain account
iboyd pass1 . Yes Local account
iboyd pass1 (empty) Yes Domain account
iboyd pass1 stackoverflow.com Yes Domain account
你想
第二个E\u NO\u认证机构
简而言之,如果你想做与
PrincipalContext.ValidateCredentials(username, password);
您需要以不同于域用户的方式处理本地用户。对于域用户,您需要调用以使用给定凭据绑定到域控制器。对于本地用户,您需要使用来使用给定的凭据绑定到WinnT://YourComputerName。这就是我在反射器中读到的PrincipalContext.ValidateCredentials
所做的
我看不出有任何等效的单一本机API为您做同样的事情。您如何调用InitializeSecurityContext
?(特别是哪个SSP?)您如何设置CredHandle
?@EdwardThomson我已经尝试了首选的协商供应商,以及NTLM
。CredHandle
是通过调用AcquireCredentialsHandle
初始化的。我似乎记得有一个类似的问题,尽管这是几年前的事了,问题还很模糊。如果使用提升的权限运行,是否有任何更改?(域名管理员可能?)@EdwardThomson我无法测试。在本地,我可以以管理员身份运行它(Windows XP),但我无法以域管理员身份运行试图验证credentails的软件。它还要求提醒:.NET不需要以管理员身份运行。是的,我没有忘记这一点,但我也不能谈论它在幕后做什么。我只是想消除一些变量。
String package = "Negotiate"; //"NTLM"
QuerySecurityPackageInfo(package, [out] packageInfo);
...
AcquireCredentialsHandle(
null, //[in] principle
package, //[in] package
SECPKG_CRED_OUTBOUND, //[in] credential use
null, //[in] LogonID
pAuthIdentity, //[in] authData
null, //[in] GetKeyFn, not used and should be null
null, //[in] GetKeyArgument, not used and should be null
credHandle, //[out] CredHandle structure
expires); //[out] expiration TimeStamp structure
Username Password Domain Machine on domain? Validate as
======== ======== ================= ================== ==============
iboyd pass1 . No Local account
iboyd pass1 (empty) No Local account
iboyd pass1 stackoverflow.com No Domain account
iboyd pass1 . Yes Local account
iboyd pass1 (empty) Yes Domain account
iboyd pass1 stackoverflow.com Yes Domain account
PrincipalContext.ValidateCredentials(username, password);