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
- Delegate sufficient privileges: http://community.spiceworks.com/how_to/show/1464-how-to-delegate-password-reset-permissions-for-your-it-staff
- Make sure that your web.config is configured so that identity impersonation element attribute is not set to “true” but set to false. This is to allow impersonation of a user through code
- Make sure that other web.config settings like forms authentication related are configured properly
3. Impersonate this account and reset or set a new password under this password “admin” account
- Sample code: http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx
- Or: http://code.msdn.microsoft.com/Reset-AD-User-Password-28d99a32#content
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”))