From http://www.cnblogs.com/sansi/archive/2010/04/27/1722510.html
Background:
Tfs2008 was set up on server A as a working group, and the account assigned to the team member is the local account of server a. In this case, if the team member wants to change the password, you need to provide a platform for modification.
The first thing that comes to mind is that the password modification page is integrated on the SharePoint Portal of TFS, but unfortunately there are some problems with Web Part controls found on the Internet, I had to create an ASP. NET page, in fact, still use directoryentry to modify. The password change Commands include "changepassword" and "setpassword". The differences between these two commands are as follows:
"Changepassword" requires an old password, which is not required for the Account to change the password.
"Setpassword" does not require the old password, but it requires the modified user to have administrator permissions.
Finally, select to useChangepasswordThe Code is as follows:
Default. aspx. CS
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web;Using System. Web. UI; Using System. Web. UI. webcontrols; Using System. directoryservices; Namespace Changepwd { Public Partial Class _ Default: system. Web. UI. Page { Protected Void Page_load ( Object Sender, eventargs e) {lableusername. Text = environment. Username ;} Protected Void Btnchangepwd_click (Object Sender, eventargs e ){ String Oldpassword = textoldpwd. Text. Trim (); String Newpassword = textnewpwd. Text. Trim (); String Newpassword2 = textnewpwd2.text. Trim (); If (Oldpassword = newpassword) {lablemsg. Text =" The new password cannot be the same as the old one. "; Return ;} Lablemsg. Text = changepassword (environment. username, oldpassword, newpassword );} Private String Changepassword (String Username, String Oldpass, String Newpass ){ String Machineanduser = environment. machinename +" \\ "+ Username; String Adspath = string. Format (" Winnt: // {0}/{1}, user ", Environment. machinename, username); directoryentry user = New Directoryentry (adspath, machineanduser, oldpass, authenticationtypes. Secure ); Try {User. Invoke ("Changepassword ", New Object [] {Oldpass, newpass }); Return String . Format (" Password Changed ");} Catch (Exception ex ){ String Message = ex. message; While (EX = ex. innerexception )! = Null ) {Message + =" :: "+ Ex. Message ;}Return Message ;} Finally {User. Dispose ();}}}}
Default. aspx:
<% @ Page Language =" C # "Autoeventwireup =" True "Codebehind =" Default. aspx. CS "Inherits =" Changepwd. _ default "%> <! Doctype HTML public" -// W3C // dtd xhtml 1.0 transitional // en "" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <HTML xmlns ="Http://www.w3.org/1999/xhtml "> <Head runat =" Server "> <Title> Change Password </title> <style type =" Text/CSS "> Body {font-family: tahoma; font-size: 14px ;}. passwordbox {width: 600px; text-align: Left ;}. passwordbox. text {width: 120px; Height: 16px; Border: 1px solid # CCC ;}. passwordbox. title {color: Blue ;}. passwordbox P {text-indent: 20px ;}. red {color: Red ;}</style> Form1 "Runat =" Server "> <Div Class =" Passwordbox "> <PClass =" Title "> <B> <asp: Label id =" Lableusername "Text =" "Runat =" Server "> </ASP: Label> </B>, where you can change the account password </P> <p> <lable> old password: </lable> <asp: textbox cssclass =" Text "Id =" Textoldpwd "Text =" "Textmode =" Password "Runat =" Server "> </ASP: textbox> <asp: requiredfieldvalidator id ="Requiredfieldvalidator1 "Runat =" Server "Errormessage =" Requiredfieldvalidator "Controltovalidate =" Textoldpwd "Text =" * "> </ASP: requiredfieldvalidator> </P> <p> <lable> New Password: </lable> <asp: textbox cssclass =" Text "Id =" Textnewpwd "Text =" "Textmode =" Password "Runat =" Server "> </ASP: textbox> <asp: requiredfieldvalidator id =" Requiredfieldvalidator2 "Runat =" Server "Errormessage =" Requiredfieldvalidator "Controltovalidate =" Textnewpwd "Text =" * "> </ASP: requiredfieldvalidator> </P> <p> <lable> confirm the new password: </lable> <asp: textbox cssclass =" Text "Id =" Textnewpwd2 "Text =" "Textmode =" Password "Runat ="Server "> </ASP: textbox> <asp: requiredfieldvalidator id =" Requiredfieldvalidator3 "Runat =" Server "Errormessage =" Requiredfieldvalidator "Controltovalidate =" Textnewpwd2 "Text =" * "> </ASP: requiredfieldvalidator> <asp: comparevalidator id =" Comparevalidator1 "Runat =" Server "Errormessage =" Comparevalidator "Controltocompare =" Textnewpwd "Controltovalidate =" Textnewpwd2 "Text =" Two new passwords are different "> </ASP: comparevalidator> </P> <P style =" Text-align: Left; padding-left: 100px; "> <Asp: button id =" Btnchangepwd "Runat =" Server "Width =" 80px "Text =" Modify "Onclick =" Btnchangepwd_click "/> </P> <p> <asp: Label id =" Lablemsg "Cssclass =" Red "Text =" "Runat =" Server "> </ASP: Label> </P> </div> </form> </body>