Friday, July 20, 2007

ChangePassword page for FBA(Form based Authentication) for SharePoint 2007

One of the nice features of SharePoint is its pluggable authentication. Its actually a ASP.NET 2.0 feature. Since SharePoint 2007 is an ASP.NET application, SharePoint inherits it for free.

SharePoint provides an out-of-the-box login.aspx page , located in 12 hives /layouts folder, which is automatically enabled when you turn on FBA on any of the Zone. There are plenty of postings on the web on how to get your forms authentication working in WSS and MOSS

What I didn't find is change password . Once you enable the form authentication, how a user can change the password? There is a ASP.NET control but nothing out-of-the-box in SharePoint, to support this

So I decided to write a custom ASPX page to handle changepassword and provision it via "Feature" . It is very simple

Here is what the final output look like. You can download the entire sample from here.
Change Password Menu Item in Welcome menu (PersonalActions)

Change Password aspx page





Here is what I did
1) Created a simple aspx page and inherited "application.master" master page. Application.Master is located in /layouts folder . You can use any of the master pages from the /layouts folder or create a custom one.
2) Drop asp:changepassword control in the content area
<asp:changepassword id="ChangePassword1" newpasswordregularexpressionerrormessage="Error: Your password must be at least 7 characters long, and contain at least one number and one special character." newpasswordregularexpression=""></asp:changepassword>
3) Copy this page to 12 hives /layouts folder
4) Create a <CustomAction> Feature set the feature URL to /_layouts/changepassword.aspx page
<customaction id="ChangePasswordMenuId" title="Change Password" description="Change Password control" sequence="2000" location="Microsoft.SharePoint.StandardMenu" groupid="PersonalActions" > <UrlAction Url="~site/_layouts/changepassword.aspx"/>

5) Install the feature using STSADM.exe


And there you go!! You have the changepassword page with very little effort.

May be Microsoft can include this as a out of the box feature in the next version of SharePoint :)




















15 comments:

Unknown said...

Hi
This is just what i have been looking for, unfortunatly i dont have the programming skills, or sufficient know how, to be able to undertake this with out some further details. any change of a more detailed guide , an example changepassword.aspx would be fab
Thanks
Joe K

Unknown said...

Hi
Thanks for this , it is just what i have been looking for. I have spent a couple of hours trying to get this to work, but have limited skills in the required area. Would it be possible to provide and example changepasword.aspx and some more detailed instructions.
many thanks
Joe K

Sheetal Jain said...

Joe

You can download the file from

http://www.docstree.com/changepassword.txt

after download, rename the file to changepassword.aspx and copy it in 12/_layouts/folder

Galexino said...

Great article. However after successful implemenentation of fba and custom action, when I click on Change Password, I am getting the following exception



Operation is not valid due to the current state of the object. at Microsoft.SharePoint.ApplicationPages.ChgPassword.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnLoad(EventArgs e)
at Microsoft.SharePoint.WebControls.LayoutsPageBase.OnLoad(EventArgs e)
at Microsoft.SharePoint.ApplicationPages.WebAdminPageBase.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


any idea on this issue?

Sheetal Jain said...

Ummer,

I have not seen this error, Are you using my code?

Where do you have the reference to Microsoft.SharePoint.ApplicationPages.ChgPassword.?

I did not have in my code. Can you post your code?

someara said...

I need some help and I'm sorry to ask for it.

could someone give me an example of how to use the stsadm tool to install this?

Thanks and sorry again for the noob question.

someara

Sheetal Jain said...

Somera

Here is msdn article on how to install feature using stsadm

http://msdn2.microsoft.com/en-us/library/ms442691.aspx

Alok said...

Hi,
I want to display "Hello" in place of "Welcome" in welcome.ascx.How can I do this. Plz help me...

Thanks in Advance
Alok...

Bob & Donna said...

I get an error when I try this code:

c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\changepassword.aspx(5): error CS0117: 'ASP._layouts_changepassword_aspx' does not contain a definition for 'OnCancelBtn' at System.Web.Compilation.AssemblyBuilder.Compile()

Anonymous said...

This is exactly what I need but I am having trouble with creating the feature. Can anyone assist ?

lbr said...

Hi, thanks for article.
I faced some issues applying your control.

Creation -

mkdir \12\TEMPLATE\FEATURES\ChangePasswordFBA
two files go there
feature.xml and operations.xml


feature.xml -

__?xml version="1.0" encoding="utf-8"?__
__Feature Id="00BAAA71-7AAD-4AA6-9BA8-C047AC750105"
Title="Change Password"
Description="Change Password"
Version="1.0.0.0"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
__ElementManifests>
__ElementManifest Location="operations.xml" />
__/ElementManifests>
__/Feature__



operations.xml -


__?xml version="1.0" encoding="utf-8"?>
__Elements
xmlns="http://schemas.microsoft.com/sharepoint/">
__CustomAction
Id="ChangePasswordMenuId"
Title="Change Password"
Description="Change Password control"
Sequence="2000"
Location="Microsoft.SharePoint.StandardMenu"
GroupId="PersonalActions">
__UrlAction Url="_layouts/changepassword.aspx"/>
__/CustomAction>
__/Elements>

replace __ with < (blogger doesn't allow those tags)


Install -

stsadm -o installfeature -filename ChangePasswordFBA\Feature.xml

stsadm -o activatefeature -filename ChangePasswordFBA\Feature.xml -url http://your_site_here


Also changepassword.aspx should be corrected -

remove -OnCancelButtonClick="OnCancelBtn" OnContinueButtonClick="OnCancelBtn"

otherwise SharePoint returns error.

Also, there is nice articel here -

http://blogs.msdn.com/sharepoint/archive/2007/10/13/announcing-the-community-kit-for-sharepoint-internet-extranet-edition-forms-based-authentication-solution.aspx

sharepoint_newbie said...

where do I put the customaction? In the changepassword.aspx

sharepoint_newbie said...

where do I put the customaction? In the changepassword.aspx page?

pmatthe1 said...

Hi

Could you please sent me a link to the source code download for this example.

Thanks in advance
Paul

Sherin said...

Hi ,
I could sucessfully implement the change password option to personal action groups.
But only a user with "full control" is able to acess the change password option.
Others are getting access denied error.
Plz help me.

Thanks
Sherin