[英]How to validate domain credentials without considering the Cached Domain Credential
我想知道是否有辦法驗證域憑據並確保我們不使用Cached Domain Credential ?
我用它來驗證憑證:
bool valid = false;
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
valid = context.ValidateCredentials( username, password );
}
問題是當我更改密碼時,舊密碼仍然有效。
編輯 :如果強制重置密碼,則不會使用緩存的域憑據 。 但是在我們強制重置的那一刻,以及用戶重置密碼的那一刻,舊密碼仍然有效。
問題已經有答案為什么Active Directory驗證上次密碼?
解決方案是使用Kerberos身份驗證。
以下代碼顯示了如何僅使用Kerberos執行憑據驗證。 如果發生故障,正在使用的身份驗證方法將不會回退到NTLM。
private const int ERROR_LOGON_FAILURE = 0x31;
private bool ValidateCredentials(string username, string password, string domain)
{
NetworkCredential credentials
= new NetworkCredential(username, password, domain);
LdapDirectoryIdentifier id = new LdapDirectoryIdentifier(domain);
using(LdapConnection connection = new LdapConnection(id, credentials, AuthType.Kerberos))
{
connection.SessionOptions.Sealing = true;
connection.SessionOptions.Signing = true;
try
{
connection.Bind();
}
catch (LdapException lEx)
{
if (ERROR_LOGON_FAILURE == lEx.ErrorCode)
{
return false;
}
throw;
}
return true;
}
你可能會嘗試這樣的事情
try
{
using (var directoryEntry = new DirectoryEntry(ldapPath, userName, password))
{
var invocation = directoryEntry.NativeObject;
return true;
}
}
catch (Exception ex)
{
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.