我想针对域控制器验证一组凭据。例如:
Username: joel
Password: splotchy
Domain: STACKOVERFLOW
在 .NET 3.5 和更新版本中,您可以使用PrincipalContext.ValidateCredentials(username, password)
.
否则你就有麻烦了。
按照 Microsoft 知识库文章如何在 Microsoft 操作系统上验证用户凭据中的代码,我到达了您调用的位置AcceptSecurityContext
:
ss = AcceptSecurityContext(
@pAS._hcred, //[in]CredHandle structure
phContext, //[in,out]CtxtHandle structure
@InBuffDesc, //[in]SecBufferDesc structure
0, //[in]context requirement flags
SECURITY_NATIVE_DREP, //[in]target data representation
@pAS._hctxt, //[in,out]CtxtHandle strcture
@OutBuffDesc, //[in,out]SecBufferDesc structure
ContextAttributes, //[out]Context attribute flags
@Lifetime); //[out]Timestamp struture
除了该功能因以下原因而失败:
SEC_E_NO_AUTHENTICATING_AUTHORITY
(0x80090311)功能失败。无法联系任何机构进行身份验证。这可能是由于以下情况:
- 认证方域名不正确。
- 域不可用。
- 信任关系失败。
这将是一个有用的错误,除了我可以使用以下方法验证来自 .NET 3.5 的相同凭据:
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
{
valid = context.ValidateCredentials(username, password);
}
会发生什么让 .NET 验证一组凭据,而本机代码却不能?
更新:LogonUser
也失败了:
LogonUser("joel@stackoverflow.com", null, "splotchy",
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_WINNT50, out token);
和
1311 - There are currently no logon servers available to service the logon request
更新二:我已经尝试过首选Negotiate
提供程序以及 Windows NT4 旧版“NTLM”提供程序
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