【问题标题】:WPF executable to ensure Windows Authentication before running?WPF可执行文件以确保在运行之前进行Windows身份验证?
【发布时间】:2013-10-15 09:50:21
【问题描述】:

我们开发了一个 WPF 应用程序,以部署在安全的环境中。每当应用程序运行/重新启动时,客户端都需要使用 Windows 身份验证重新对应用程序进行身份验证。我们如何使用 WPF 应用程序做到这一点?

【问题讨论】:

    标签: c# wpf windows-authentication access-control


    【解决方案1】:

    如果您想针对本地系统帐户执行此操作,

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)
    {
        if (pc.ValidateCredentials(username, password))
        {
            /* Check group membership */
        }
    }
    

    如果你想对抗AD,

     public bool AuthenticateUser(string domainName, string userName,
      string password)
    {
      bool ret = false;
    
      try
      {
        DirectoryEntry de = new DirectoryEntry("LDAP://" + domainName,
                                               userName, password);
        DirectorySearcher dsearch = new DirectorySearcher(de);
        SearchResult results = null;
    
        results = dsearch.FindOne();
    
        ret = true;
      }
      catch
      {
        ret = false;
      }
    
      return ret;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 2012-12-18
      • 2012-03-11
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      相关资源
      最近更新 更多