icube
icube

Reputation: 2798

WPF executable to ensure Windows Authentication before running?

We have a WPF app that we develop to be deployed in a secure environment. The client requires the app to be re authenticated with the Windows Authentication whenever the app runs/restart. How do we do that with WPF application?

Upvotes: 0

Views: 1143

Answers (1)

Rajesh Subramanian
Rajesh Subramanian

Reputation: 6490

If you want to do it against local system account,

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

If you want to do against 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;
}

Upvotes: 1

Related Questions