Changing Active Directory user passwords in a .NET Web Application

Here are some tips on how to allow your web application to change passwords to Active Directory. There are several ways which all work in a similar but different way. This is one of them and what you need to take into consideration.

Here I will concentrate in the code logic and configurations what you need to take and do.

These are the following steps you need to take:

1. Create a web form for you password reset

2. Create a account with just enough privileges to set or reset user passwords

3. Impersonate this account and reset or set a new password under this password “admin” account

And a small sample code on how to change a password:

using (var context = new PrincipalContext(ContextType.Domain, “domain”, “username”, “password”))


     using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, “username whose password to change”))



//// or

                                    //user.ChangePassword(“oldPassword”, “newpassword”);





Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s