根据Active Directory验证用户名和密码?如何针对Active Directory验证用户名和密码?我只想检查用户名和密码是否正确。
3 回答
噜噜哒
TA贡献1784条经验 获得超7个赞
using (DirectoryEntry adsEntry = new DirectoryEntry(path, strAccountId, strPassword)){
using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
{
//adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")";
try
{
SearchResult adsSearchResult = adsSearcher.FindOne();
bSucceeded = true;
strAuthenticatedBy = "Active Directory";
strError = "User has been authenticated by Active Directory.";
}
catch (Exception ex)
{
// Failed to authenticate. Most likely it is caused by unknown user
// id or bad strPassword.
strError = ex.Message;
}
finally
{
adsEntry.Close();
}
}}- 3 回答
- 0 关注
- 967 浏览
添加回答
举报
0/150
提交
取消
