15 November 2010

Active Directory: Password Management using SharePoint Webpart.

For Active Directory member the password management is one of the vital functionality which developer needs to add in his efforts to provide a appropriate solution.
Here below is the code snipplet to achieve this functionality.

I have implemented using SharePoint Webpart.

please specify you validation accordingly.
-:Core Code:-

WindowsImpersonationContext aspContext = null;
WindowsIdentity identity = WindowsIdentity.GetCurrent();
aspContext = identity.Impersonate();
ContextOptions o = ContextOptions.Negotiate;
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, this._DomainName, this._DomainName Path);

UserPrincipal UPrinci = new UserPrincipal(ctx);
UPrinci = UserPrincipal.FindByIdentity(ctx, SPContext.Current.Web.CurrentUser.LoginName);
UPrinci.ChangePassword(_oldpassword.Text, _newpassword.Text);
_labelmsg.Text = "Password changed successfully!" ;
} //Try
catch (PasswordException ex)
{ //ex.Message; Catch exception.}
} //Delegate


Let me know your comments/ exceptions etc.
Will be glad to get back to you.

No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: