Using Change Password ASP.NET control in SharePoint 2010 FBA.

Create a new SharePoint 2010 Empty Project in visual studio 2010.

Right click the project à Add New Itemà Select “Application Page”.

Add the ChangePassword control inside PlaceHolderMain content place holder

<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>

<asp:ChangePassword
id=”myChangePassword”
newpasswordregularexpressionerrormessage=”Error: Your password must be at least 5 characters long, and contain at least one number and one special character.” runat=”server” CancelDestinationPageUrl=”~/pages/default.aspx” OnContinueButtonClick=”ContinueClickHandler” MembershipProvider=”SqlMembers”  OnChangingPassword=”ChangingPassword” OnChangedPassword=”ChangedPassword”></asp:ChangePassword></asp:Content>

Put the following code for OnChangingPassword and OnChangedPassword Event handler in the code behind. 

 // the username would be in the following format
 // 0#.f|sqlmembers|nishantr
 // so we need to get only the username part
 // otherwise it wont work properly
protected void ChangingPassword(object sender, EventArgs e)
{
System.Web.UI.WebControls.ChangePassword chngPassword = (System.Web.UI.WebControls.ChangePassword)sender;
chngPassword.UserName = chngPassword.UserName.Substring(chngPassword.UserName.LastIndexOf("|") + 1);
}

// add reference to Microsoft.SharePoint.IdentityModel dll
protected void ChangedPassword(object sender, EventArgs e)
{
System.Web.UI.WebControls.ChangePassword chngPassword = (System.Web.UI.WebControls.ChangePassword)sender;
FormsAuthentication.SignOut();
Microsoft.SharePoint.IdentityModel.SPClaimsUtility.AuthenticateFormsUser(new Uri(SPContext.Current.Web.Url), chngPassword.UserName, chngPassword.NewPassword);
}


Check this really helpful pack

http://sharepoint2010fba.codeplex.com/

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

3 thoughts on “Using Change Password ASP.NET control in SharePoint 2010 FBA.”

Share your thoughts

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

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