title: using windows username password in C#
body: <p>how i can use windows stored username and password in my C# APP. I am looking for method which returns bool state of successful login. means :</p>
  
  <pre><code>bool isCredentialValid = CheckLogin(username, password);
  </code></pre>
  
  <p>so according to bool value I can show proper message.</p>
  
  <p><strong>Updated</strong></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          PrincipalContext pc = new PrincipalContext(ContextType.Machine);
          Console.WriteLine("Enter username : ");
          string user = Console.ReadLine();
  
          Console.WriteLine("Enter password : ");
          string pass = Console.ReadLine();
  
          bool isValid = pc.ValidateCredentials(user, pass);
  
          Console.WriteLine("State : {0}",isValid);
  
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>this code is not working. when i enable <strong>Guest account</strong> it shows true for every login and when i disable <strong>Guest account</strong> it does not verifies even existing account. Any help would be appreciated.</p>