Copied to clipboard

Flag this post as spam?

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


  • Mila Pandurska 75 posts 350 karma points
    Oct 17, 2019 @ 12:04
    Mila Pandurska
    0

    Change Password, Reset password

    Hi

    I have Umbraco 8.2.0 project and I have user accounts (members) which needs to login and edit their details. I cannot find how to:

    1.What is the recommended way to create new member? I have the code bellow, but I am not sure that it is the right way in Umbraco 8:

     private readonly IMemberService _memberService;
    
            public MemberController(IMemberService memberService, IMembershipUserService a)
            {
                this._memberService = memberService;
            }
    
            public ActionResult RegisterMember(RegisterModel model)
            {
                if (ModelState.IsValid)
                {
                           var member = _memberService.CreateMember(model.UserName, model.Email, model.Name, "Member");
                            _memberService.Save(member);
                            _memberService.SavePassword(member, model.Password);
                 }
             }
    
    1. Change member password from account page. Here I cannot find ChangePassword method in IMemberService which takes the old password, verify it and save the new password.

    2. Implement forgotten password functionality - send an email with reset token and then redirect to reset password page.

    Any documentation/ideas will be helpfull

    Mila

  • Anthony Powell 12 posts 46 karma points
    1 week ago
    Anthony Powell
    0

    Hi Mila,

    This is a really old post, but I'm actively attempt to close these old posts with no answer, since they have such good SEO ranking. It'll help others.

    So from my understanding there are 2 things to consider here. You have the:

    1. Umbraco.Core.Services.Implement.MemberService
    2. Umbraco.Web.Security.MembershipHelper

    Both seem to have methods for changing passwords. They can both be injected via the constructor.

    Use this to set the password if you don't know or care about the old one.

    var member = _memberService.GetById(_membershipHelper.GetCurrentMemberId()); 
    _memberService.SavePassword(member, model.Password);
    

    Or this if you have the old password.

    _membershipHelper.ChangePassword(username, new ChangingPasswordModel(), MembershipProvider);
    

    Here are the ChangePassworkModel Properties enter image description here

    Hope that helps anyone with a similar issue.

Please Sign in or register to post replies

Write your reply to:

Draft