[英]Custom Multi-factor Active Directory Authentication
首先,我說我不知道我想要的東西是否可以實際完成。 如果是這樣,請立即告訴我我在做夢。
我想在C#中創建一個自定義活動目錄“ authenticator”。 我的意思是,我希望每當有人登錄時,首先檢查其存儲在AD中的密碼,然后執行第二步身份驗證。 只有兩個步驟都通過,用戶才能登錄。
現在,我想上述內容並不太復雜,只要我想將此身份驗證器集成到定制產品中,對嗎? 我是否還在想知道是否可以在登錄Windows本身時使用此身份驗證器? 還是可能存在針對AD進行身份驗證的產品?
如果我不做夢,誰還會知道任何好的文章/ API來幫助我前進? API不必免費,因為我願意花一些錢來使事情進展得更快。
這是完全可行的。 但是,我想指出的是,在將服務器綁定到Active Directory時,您正在檢查提供的用戶名(通常為sAMAccountName)和在一個操作中輸入的密碼。 在C#中有幾種方法可以做到這一點,但是許多人(包括我自己)都選擇使用System.DirectoryServices
和System.DirectoryServices.Protocols
命名空間。
這就是我當前將用戶綁定到Active Directory的方式,然后基於此方法的結果,我要么顯示授權失敗的原因,要么允許他們繼續使用應用程序中的帳戶。
//Define your connection
LdapConnection ldapConnection = new LdapConnection("123.456.789.10:389");
try
{
//Authenticate the username and password
using (ldapConnection)
{
//Pass in the network creds, and the domain.
var networkCredential = new NetworkCredential(Username, Password, Domain);
//Since we're using unsecured port 389, set to false. If using port 636 over SSL, set this to true.
ldapConnection.SessionOptions.SecureSocketLayer = false;
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
//To force NTLM\Kerberos use AuthType.Negotiate, for non-TLS and unsecured, use AuthType.Basic
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.Bind(networkCredential);
}
catch (LdapException ldapException)
{
//Authentication failed, exception will dictate why
}
}
如果您想進一步查找該用戶的屬性, 請在此處查看此線程 。
此外,我強烈推薦Softerra的LDAP瀏覽器來測試與LDAP相關的任何內容-這是一個很棒的產品,而且是免費的。 您可以從這里下載。
希望這能使您朝正確的方向前進。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.