.NET: Using AD to change a users Password and get Password expiry date

1. Add reference to ActiveDS.tlb (still most AD interfaces are in COM)

2. Following is code from a lot of online sites merged/tested together for a complete working solution.

 string path =
 "LDAP://"+"ldapserver"+"/CN="+"username-to-test"+"," + "CN=Users,DC=domain1,DC=main-domain";
 try
 {
 	DirectoryEntry entry = new DirectoryEntry(path, "known-user", "known-password",
 		AuthenticationTypes.ServerBind);
 	// Create the Directory search instance.
 	DirectorySearcher search = new DirectorySearcher(entry);
 	// Set the search string. The search is on username.
 	SearchResult result = search.FindOne();
 	// If the username has been found in the LDAP server.	if(null != result)
 	{
 		// The result obtained will look like the following:
 		// CN=group1,CN=group2,DC=domain1,DC=main-domain
 		if (result.Properties.Contains("memberof"))
 		{
 		//Print the list of members this user belongs to as a test
 		for(int i=0; i
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: