see if this can help u
protected bool ActiveDirectoryLogin(string Username, string Password, string Domain) { bool Success = false; //System.DirectoryServices.DirectoryEntry Entry = // new System.DirectoryServices.DirectoryEntry("LDAP://196.15.32.161:389/cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa", "uid=" + Username + ",cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa", Password, AuthenticationTypes.None); System.DirectoryServices.DirectoryEntry Entry = new System.DirectoryServices.DirectoryEntry("LDAP://ldapmaster.kfupm.edu.sa:389/cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa", "uid=" + Username + ",cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa", Password,AuthenticationTypes.None); //System.DirectoryServices.DirectoryEntry Entry = // new System.DirectoryServices.DirectoryEntry("LDAP://ldapmaster.kfupm.edu.sa:389/cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa", Username , Password, AuthenticationTypes.None); System.DirectoryServices.DirectorySearcher Searcher = new System.DirectoryServices.DirectorySearcher(Entry); //Entry.Username = "uid="+Username + ",cn=KFUPM-People,o=KFUPM,dc=kfupm,dc=edu,dc=sa"; //Entry.Password = Password; //Entry.AuthenticationType = AuthenticationTypes.None; // Searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree; try { Object nat = Entry.NativeObject; Success = true; // System.DirectoryServices.SearchResult Results = Searcher.FindOne(); // Success = (Results != null); } catch (Exception e) { Success = false; } return Success; }
source share