Authentication 针对Active Directory的身份验证。。董事搜索的必要性
我有下面的代码来根据Active Directory验证给定的用户名和密码Authentication 针对Active Directory的身份验证。。董事搜索的必要性,authentication,active-directory,ldap,Authentication,Active Directory,Ldap,我有下面的代码来根据Active Directory验证给定的用户名和密码 DirectoryEntry entryInAbsg = new DirectoryEntry("LDAP://....../DC=....,DC=..", username, password,AuthenticationTypes.Secure); object nativeObject = entryInAbsg.NativeObject; authenticated
DirectoryEntry entryInAbsg = new DirectoryEntry("LDAP://....../DC=....,DC=..", username, password,AuthenticationTypes.Secure);
object nativeObject = entryInAbsg.NativeObject;
authenticated = true;
这是否足以验证用户?是否需要使用DirectorySearcher再次搜索用户?
上述用户名和密码应为管理员帐户?,足以验证用户。但要执行搜索,您需要创建DirectorySeacher的实例,并将DirectoryEntry对象(EntryNabsg)以及您可能需要的任何筛选器传递给构造函数。考虑下面C中的例子; 您可以根据自己的具体需要定制
private DirectorySeacher GetDirectorySeacher(DirectoryEntry entryInAbsg)
{
DirectorySearcher dirSeach = null;
if(dirSearch == null)
{
try
{
dirSearch = new DirectorySeacher(entryInAbsg)
}
catch (DirectoryServicesCOMException e)
{
MessageBox.Show("Authentification Failed!!!, Please Check.", "Error Info", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return dirSearch;
}
else
{
return dirSearch;
}
}