代码之家  ›  专栏  ›  技术社区  ›  Kaiser Advisor

C中对Active Directory的通用身份验证调用#

  •  0
  • Kaiser Advisor  · 技术社区  · 17 年前

    我希望有一个干净的C#类,可以从Active Directory进行身份验证。

    这应该是相当简单的,它只需要要求的凭据,并检查它是否符合广告的期望。

    我负责许多C#应用程序,我希望它们都使用同一个类。

    3 回复  |  直到 14 年前
        1
  •  7
  •   Bob    17 年前

    http://support.microsoft.com/kb/316748

    public bool IsAuthenticated(String domain, String username, String pwd)
    {
      String domainAndUsername = domain + "\\" + username;
      DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
    
      try
      { //Bind to the native AdsObject to force authentication.         
         Object obj = entry.NativeObject;
    
         DirectorySearcher search = new DirectorySearcher(entry);
    
         search.Filter = "(SAMAccountName=" + username + ")";
         search.PropertiesToLoad.Add("cn");
         SearchResult result = search.FindOne();
    
         if(null == result)
         {
             return false;
         }
    
         //Update the new path to the user in the directory.
         _path = result.Path;
         _filterAttribute = (String)result.Properties["cn"][0];
      }
      catch (Exception ex)
      {
         throw new Exception("Error authenticating user. " + ex.Message);
      }
    
         return true;
     }
    
        2
  •  2
  •   Inisheer    17 年前

    诚然,我没有针对广告编程的经验,但下面的链接似乎可以解决您的问题。

    http://www.codeproject.com/KB/system/everythingInAD.aspx#35

        3
  •  1
  •   Pontus Gagge    17 年前

    有些原因你不能用 Windows integrated authentication ,而不麻烦用户输入他们的姓名和密码?如果可能的话,这同时是最可用和安全的解决方案。