我有一个Web应用程序,其中包含登录页面。 我如何对活动目录用户进行身份验证?
到目前为止,我能够从活动目录中获取一些属性,这表明我能够使用LDAP字符串与AD通信。 我知道不可能从AD中提取密码并对用户输入的密码进行身份验证!
有没有办法对活动目录用户进行身份验证?
以下是我的代码:
public class Userdetails
{
public static string ADPath = ConfigurationManager.AppSettings.Get(“ADPath”); // Get the ADAM Path from web config fiel
public static string ADUser = ConfigurationManager.AppSettings.Get(“ADUser”); //ADAM Administrator
public static string ADPassword = ConfigurationManager.AppSettings.Get(“ADPassword”); //ADAM Administrator password
public static DirectoryEntry GetUserDetails(string userID)
{
AuthenticationTypes AuthTypes; // Authentication flags.
// Set authentication flags.
// For non-secure connection, use LDAP port and
// ADS_USE_SIGNING |
// ADS_USE_SEALING |
// ADS_SECURE_AUTHENTICATION
// For secure connection, use SSL port and
// ADS_USE_SSL | ADS_SECURE_AUTHENTICATION
AuthTypes = AuthenticationTypes.Signing |
AuthenticationTypes.Sealing |
AuthenticationTypes.Secure;
DirectoryEntry De = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthTypes);
DirectorySearcher Ds = new DirectorySearcher(De);
SearchResult Sr;
Ds.SearchScope = SearchScope.Subtree;
Ds.Filter = “(&(objectclass=*)(cn= ” + userID + “))”;
Sr = Ds.FindOne();
if (!(Sr == null))
{
De = new DirectoryEntry(Sr.Path, ADUser, ADPassword, AuthTypes);
return De;
}
else
{
return null;
}
}