
























代码
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;namespace ChangeControlApp
{
class LdapAuthentication
{
private String _path;
private String _filterAttribute;public LdapAuthentication(String path)
{
_path = path;
}public bool IsAuthenticated(String domain, String username, String pwd)
{
String domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);try
{ //Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search
= new DirectorySearcher(entry);search.Filter
= "(SAMAccountName=" + username + ")";String dn;
int equalsIndex, commaIndex;for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)equalsIndex
= dn.IndexOf("=", 1);groupNames.Append(dn.Substring((equalsIndex
+ 1), (commaIndex - equalsIndex) - 1)); }
}
}
}
ad path 传值类似:LDAP://Asia2.ccb2.com
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。