Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF可执行文件在运行前确保Windows身份验证?_C#_Wpf_Windows Authentication_Access Control - Fatal编程技术网

C# WPF可执行文件在运行前确保Windows身份验证?

C# WPF可执行文件在运行前确保Windows身份验证?,c#,wpf,windows-authentication,access-control,C#,Wpf,Windows Authentication,Access Control,我们开发了一个WPF应用程序,可以部署在安全的环境中。每当应用程序运行/重新启动时,客户端要求应用程序使用Windows身份验证重新进行身份验证。我们如何使用WPF应用程序做到这一点 如果您想对本地系统帐户执行此操作 using (PrincipalContext pc = new PrincipalContext(ContextType.Domain) { if (pc.ValidateCredentials(username, password)) { /*

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

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

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)
{
    if (pc.ValidateCredentials(username, password))
    {
        /* Check group membership */
    }
}
如果你想对抗广告

 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;
}