csharp 验证LDAP服务器中的用户
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 验证LDAP服务器中的用户相关的知识,希望对你有一定的参考价值。
public static bool IsAuthenticated(string username, string pwd)
{
try
{
string domain = ContentValue.GetByParameterName("ActiveDirectoryDomain", 0, "en").Value.ToString();
SendEventLogForDebugging("System Script", "IsAuthenticated", "Domain: " + domain);
string path = ConfigurationManager.ConnectionStrings["LdapAuthenticationPath"].ConnectionString;
SendEventLogForDebugging("System Script", "IsAuthenticated", "Path: " + path);
String domainAndUsername = domain + @"\" + username;
SendEventLogForDebugging("System Script", "IsAuthenticated", "domainAndUsername: " + domainAndUsername);
DirectoryEntry entry = new DirectoryEntry(path, domainAndUsername, pwd);
//DirectoryEntry entry = new DirectoryEntry(path, domainAndUsername, pwd, AuthenticationTypes.SecureSocketsLayer);
//Bind to the native AdsObject to force authentication.
//Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
SendEventLogForDebugging("System Script", "IsAuthenticated", "Username and password is Not authenticate");
return false;
}
else
{
SendEventLogForDebugging("System Script", "IsAuthenticated", "Username and password is authenticate");
return true;
}
}
catch (Exception ex)
{
SendEventLog(EventLogEntryType.Error.ToString(), "SystemScript - IsAuthenticated", ex.ToString());
SendEventLogForDebugging("System Script", "IsAuthenticated", ex.Message);
return false;
}
}
以上是关于csharp 验证LDAP服务器中的用户的主要内容,如果未能解决你的问题,请参考以下文章
LDAP 身份验证通过凭据
ALM 中的 LDAP 实施,现有用户具有数据库身份验证的问题
windows的域使用openldap作为用户权限认证
Hive 中的 Ldap 身份验证用户过滤器:失败
LDAP 身份验证超时
使用 LDAP 服务器对用户进行身份验证