2
votes

I need a functionality to change umbraco member password programatically.user can add their new password in the field I had set on umbraco node.and when they publish the node new password will come in effect.I had find a way to change current password to given one

 member.ChangePassword(oldPassword, password);

But this requires oldpassword to work.and I cant provide it as user has already changed old password in the umbraco node.then I tried to get old password programatically.

 string theUserPassword = Membership.GetUser(username).GetPassword();

but this also throws an error

Password Retrieval Not Enabled.

Is there any way to get old password programatically?Or Am I going in the wrong direction?

3

3 Answers

3
votes

I know this is an old post and an answer has already been accepted, but you can actually achieve what the OP wants to do by using the return value of the ResetPassword method for the oldValue parameter of the ChangePassword method:

member.ChangePassword(member.ResetPassword(), "New Password")

This allows you to change the password for a user to a specific value without knowing their existing password.

2
votes

Umbraco uses the Microsoft Membership Provider. You probably have set the property "EnablePasswordRetrieval" to false.

If you don't know the password but need to change it, you can reset the password bij using the ResetPassword method.

2
votes

Another option to an old question:

I am using Umbraco 7.2.4 and here is how I change the password.

var member = Services.MemberService.GetByUsername("username");
Services.MemberService.SavePassword(member, "new password");

Where "Services.MemberService" is from ApplicationContext.Current.Services.MemberService.

The first line of code is where you get the member for which you want to change the password. This can also be done by email or id.

Services.MemberService.GetByEmail("email")
Services.MemberService.GetById(id)

The second line is where you change the password. It is automatically hashed.