相关疑难解决方法(0)

Active Directory - 检查用户名/密码

我在Windows Vista Ultimate SP1上使用以下代码来查询我们的活动目录服务器以检查域上用户的用户名和密码.

public Object IsAuthenticated()
{
    String domainAndUsername = strDomain + "\\" + strUser;
    DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, strPass);
    SearchResult result;
    try
    {
        //Bind to the native AdsObject to force authentication.         

        DirectorySearcher search = new DirectorySearcher(entry) { Filter = ("(SAMAccountName=" + strUser + ")") };

        search.PropertiesToLoad.Add("givenName"); // First Name                
        search.PropertiesToLoad.Add("sn"); // Last Name
        search.PropertiesToLoad.Add("cn"); // Last Name

        result = search.FindOne();

        if (null == result)
        {
            return null;
        }

        //Update the new path to the user in …
Run Code Online (Sandbox Code Playgroud)

c# ldap active-directory windows-vista

34
推荐指数
2
解决办法
7万
查看次数

标签 统计

active-directory ×1

c# ×1

ldap ×1

windows-vista ×1