Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren Eccles 59 posts 298 karma points
    May 15, 2017 @ 11:22
    Darren Eccles
    2

    Problem updating members password using umbraco version 7.6.1

    Just wonder if anyone can help.

    I'm trying to update the members password with the following code:

    var memberService = Services.MemberService;
    var member = memberService.GetById(model.Id);
    memberService.SavePassword(member, model.Password);
    

    However, when I run the code I get the following error:

    System.NotSupportedException: This provider does not support manually changing the password at Umbraco.Core.Security.MembershipProviderBase.ChangePassword(String username, String oldPassword, String newPassword) at Umbraco.Core.Services.MemberService.SavePassword(IMember member, String password)

    I have the same code on other sites and it works, what am I doing wrong?

    Thanks

    Darren

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 15, 2017 @ 11:33
    Sebastiaan Janssen
    9

    You have set allowManuallyChangingPassword="false" in your web.config file on the UmbracoMembershipProvider, which is best practice. This ensures that you provide the old password AND the changed password so people can not randomly change your password if you step away from your computer for a second and forget to lock it.

    If you are not currently asking for the old password or can't/don't want to then set allowManuallyChangingPassword="true" on the UmbracoMembershipProvider.

  • Damien Holley 180 posts 541 karma points
    Nov 02, 2017 @ 07:25
    Damien Holley
    0

    Is there any way of doing this programmatically?

  • Darren Eccles 59 posts 298 karma points
    May 15, 2017 @ 11:44
    Darren Eccles
    2

    Hi Sebastiaan,

    Thank you very much, that works :)

    How would I go about passing the old password in?

    The 'Services.MemberService.SavePassword()' only takes two parameters:

    • IMember
    • String (Password)

    Thanks again

    Darren

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 15, 2017 @ 12:04
    Sebastiaan Janssen
    1

    Ah, this is a very good point! We should have an additional method that supports passing in the old password. Could you create an issue for that on http://issues.umbraco.org please?

  • Darren Eccles 59 posts 298 karma points
    May 15, 2017 @ 13:52
    Darren Eccles
    4

    Hi Sebastiaan,

    I've created an issue report on http://issues.umbraco.org

    Thanks again for your help

    Darren

  • Harvey 28 posts 122 karma points
    May 18, 2017 @ 16:05
    Harvey
    1

    Just came across this issue!

    How does Umbraco change a member/user password? There is an option to reset a member's/user's password in the backoffice without knowing the old password.

    In my code, I may need to use different methods depending on the scenarios:

    • a method for when I need to reset a password without knowing their password (as in they forgot it, and I have gone through the steps to authenticate them)
    • a method for resetting a password with an old password (being addressed in http://issues.umbraco.org/issue/U4-9917)

    In order to address the first scenario above, do I have to set allowManuallyChangingPassword="true"?

  • Chris Morley 12 posts 103 karma points
    Jun 04, 2017 @ 15:35
    Chris Morley
    0

    Hi Sebastiaan

    I'm having a similar issue, but with newly created accounts (as in through a register controller), How do you create a new user and set a password that the user enters though a registration form?

    I've currently got:

            //convert model to Register
            var newUser = Services.MemberService.CreateMember(model.Email, model.Email, model.Email, "user");
            memberService.SavePassword(newUser, model.Password);
            memberService.Save(newUser);
    

    But i'm getting the same error above: System.NotSupportedException: This provider does not support manually changing the password

    How do you set a newly created members password when your creating them in Umbraco?

    Many thanks Chris

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jun 04, 2017 @ 15:43
    Sebastiaan Janssen
    4

    Currently the only workaround is to set allowManuallyChangingPassword="true" on the UmbracoMembershipProvider.

    This will be fixed soon (hopefully for the next release), follow this issue: http://issues.umbraco.org/issue/U4-9917

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jun 16, 2017 @ 09:31
    Bjarne Fyrstenborg
    0

    I have a similar issue as Chris for a registration form, which has password and password confirm fields.

    var member = ms.CreateMemberWithIdentity(model.Email, model.Email, model.Name, "member");
    ms.Save(member);
    
    ms.AssignRole(member.Id, "Customer");
    ms.SavePassword(member, model.Password);
    

    enter image description here

    Changing allowManuallyChangingPassword to true fixed it for now.

    I am running on Umbraco v. 7.6.3

    /Bjarne

  • Jamie Attwood 207 posts 501 karma points c-trib
    Oct 18, 2018 @ 19:05
    Jamie Attwood
    2

    Hi there, not sure if you ever resolved this, but after days (literally) I came up with the following using exclusively the member service. Note the order of saving the member is very important here as you are likely saving a password into a member that does not exist yet...

    Here is the controller -hope this helps...

    [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Register(AccountModels.RegistrationModel model)
        {           
                if (ModelState.IsValid)
                {
                    try
                    {
    
                    var memberService = Services.MemberService;
    
                    if (memberService.Exists(model.Email))
                        {
                            ModelState.AddModelError(String.Empty, "Member already exists with this email address");
                            return CurrentUmbracoPage();
                        }
    
                    var member = memberService.CreateMember(model.Email, model.Email, model.FirstName + " " + model.LastName, "Client");
    
                    //Now add custom attributes to the user type
                    member.SetValue("firstName", model.FirstName);
                    member.SetValue("lastName", model.LastName);
                    member.IsApproved = true;
                    //Save the member!!
                    memberService.Save(member);
    
                    //Assign role
                    memberService.AssignRole(member.Id, "Client");
    
                    // save member first, then save their password as there would be no member to save into otherwise
                    memberService.SavePassword(member, model.Password);
    
                    //Check to see now if the member really exists. If so, login and redirect...
                    if (memberService.Exists(member.Id))
                    {
                        FormsAuthentication.SetAuthCookie(model.Email, false);
                        return Redirect("/account/");
                    }
                }
                catch (Exception e)
                    {
                        ModelState.AddModelError("", "Could not create new user. Exception details: " + e);
                    }
    
            }
    
            return CurrentUmbracoPage();
        }
    

    Cheers,

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft