Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. using (DirectoryEntry entry = new DirectoryEntry())
  2. {
  3. entry.Username = "here goes the username you want to validate";
  4. entry.Password = "here goes the password";
  5.  
  6. DirectorySearcher searcher = new DirectorySearcher(entry);
  7.  
  8. searcher.Filter = "(objectclass=user)";
  9.  
  10. try
  11. {
  12. searcher.FindOne();
  13. }
  14. catch (COMException ex)
  15. {
  16. if (ex.ErrorCode == -2147023570)
  17. {
  18. // Login or password is incorrect
  19. }
  20. }
  21. }
  22.  
  23. // FindOne() didn't throw, the credentials are correct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement