ldap 인증의 일반적인 절차
2743 단어 LDAP 인증
이 5가지 단계는 LDAP 기반의 "2회 바인딩"검증 방법입니다.
<span style="font-size:18px;">bool checkResult = false;
try
{
string username = Request.Params.Get("username");
string userpwd = Request.Params.Get("userpwd");
string strLADPath = "LDAP://OU= ,DC=HOLD,DC=Company,DC=COM";
DirectoryEntry objEntry = new DirectoryEntry(strLADPath);
objEntry.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher deSearch = new DirectorySearcher(objEntry);
//
deSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + username + "))";
deSearch.SearchScope = SearchScope.Subtree;
//find the first instance
SearchResult results = deSearch.FindOne();
//check username & userpwd
if (null != results)
{
DirectoryEntry objUserEntry = new DirectoryEntry(results.Path, username, userpwd);
if (null != objUserEntry && null != objUserEntry.Properties
&& objUserEntry.Properties.Contains("cn"))
{
checkResult = true;
}
}
Response.Write(" :" + checkResult.ToString());
}
catch (System.Exception ex)
{
Response.Write(" "+ex.StackTrace);
Response.Write(" :" + checkResult.ToString());
}</span>