转:YetAnotherForum集成AD用户混合登录(一) AD验证类

YetAnotherForum集成AD用户混合登录(一) AD验证类

 public class AD_pass
{
private string _path;
private string _filterAttribute;

public AD_pass()
{

_path
= "LDAP://DC=office,DC=local";

}


public bool IsAuthenticated(string username, string pwd)
{


try
{
DirectoryEntry entry
= new DirectoryEntry(_path, username, pwd);

Object obj
= entry.NativeObject;
DirectorySearcher search
= new DirectorySearcher(entry);
search.Filter
= "(SAMAccountName=" + username + ")";
SearchResult result
= search.FindOne();
if (null == result)
{
return false;
}
_path
= result.Path;
_filterAttribute
= (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
return false;
}
return true;
}
}

posted on 2009-04-10 13:45  沸石  阅读(460)  评论(1编辑  收藏  举报

导航