} // End Sub cbIntegratedSecurity_CheckedChanged static void test() { string domainAndUsername = string.Empty; string domain = string.Empty; string userName = string.Empty; string passWord = string.Empty; System.DirectoryServices.AuthenticationTypes at = System.DirectoryServices.AuthenticationTypes.Anonymous; System.Text.StringBuilder sb = new System.Text.StringBuilder(); domain = @"LDAP://w.x.y.z"; domainAndUsername = @"LDAP://w.x.y.z/cn=Lawrence E." + @" Smithmier\, Jr.,cn=Users,dc=corp," + "dc=productiveedge,dc=com"; userName = "******"; passWord = "******"; at = System.DirectoryServices.AuthenticationTypes.Secure; System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(domain, userName, passWord, at); System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry); System.DirectoryServices.SearchResultCollection results; string filter = "maxPwdAge=*"; mySearcher.Filter = filter; results = mySearcher.FindAll(); long maxDays = 0; if (results.Count >= 1) { long maxPwdAge = (long)results[0].Properties["maxPwdAge"][0]; maxDays = maxPwdAge / -864000000000; } // End if (results.Count >= 1) System.DirectoryServices.DirectoryEntry entryUser = new System.DirectoryServices.DirectoryEntry(domainAndUsername, userName, passWord, at); mySearcher = new System.DirectoryServices.DirectorySearcher(entryUser); results = mySearcher.FindAll(); long daysLeft = 0; if (results.Count >= 1) { var lastChanged = results[0].Properties["pwdLastSet"][0]; daysLeft = maxDays - System.DateTime.Today.Subtract(System.DateTime.FromFileTime((long)lastChanged)).Days; } // End if (results.Count >= 1) System.Console.WriteLine("You must change your password within {0} days", daysLeft); System.Console.ReadLine(); }
/// <summary> /// Initializes a new instance of the <c>TreeStrategyDirectoryServices</c> class. /// </summary> /// <param name="authenticationType">Used AuthenticationType</param> /// <param name="credential">Credential used to retrieve Data from the Directory Services.</param> public TreeStrategyDirectoryServices(System.Net.NetworkCredential credential, System.DirectoryServices.AuthenticationTypes authenticationType) : this() { this._credential = credential; this._authenticationType = authenticationType; }
/// <summary> /// Initializes a new instance of the <c>TreeStrategyDirectoryServices</c> class. /// </summary> /// <param name="authenticationType">Used AuthenticationType</param> /// <param name="credential">Credential used to retrieve Data from the Directory Services.</param> public TreeStrategyDirectoryServices(System.Net.NetworkCredential credential, System.DirectoryServices.AuthenticationTypes authenticationType) : this() { this._credential = credential; this._authenticationType = authenticationType; }