SoFunction
Updated on 2025-03-07

Detailed explanation of C# using AD (Active Directory) to verify intranet username and password

Detailed explanation of C# using AD (Active Directory) to verify intranet username and password

1. Connect to the intranet and find the domain address of AD

nslookup 
set types=all
_ldap._tcp

2. Verify AD functions

public bool ADLogin(string userName, string password) 
    { 
      // sample : 
      // LDAP:// 
      string domain = ["AD_Domain"]; 
       
      try 
      { 
        DirectoryEntry entry = new DirectoryEntry(domain, userName, password); 
        object obj = ; 
        DirectorySearcher search = new DirectorySearcher(entry); 
         = ("(SAMAccountName={0})", userName); 
        ("cn"); 
 
 
        SearchResult result = (); 
        if (result == null) 
          return false; 
      } 
      catch (Exception ex) 
      { 
        (ex); 
        return false; 
      } 
 
 
      return true; 
    } 



If you have any questions, please leave a message or go to the community of this site to exchange and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!