Copied to clipboard

Flag this post as spam?

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


  • Linx 98 posts 258 karma points
    Mar 21, 2023 @ 15:12
    Linx
    0

    Resetting Member password

    Hi

    Ive been going through some threads in order to reset a Member password. Some of the examples are for another version of Umbraco (im after v 10) or if they seem close to what im after i dont seem to have a method that does the trick. Others suggest i need to change the web.config but i dont have a web.config as its running under Umbraco 10 which is on .Net Core.

    Could someone give me an example of how to change a members password please?

    Many thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 21, 2023 @ 15:38
    Huw Reddick
    1

    you can use the memberManager.ChangePasswordAsync method

    something like

                var member = _memberManager.GetCurrentMemberAsync().Result;
                if (member != null)
                {
                    var changePasswordResult =
                        await _memberManager.ChangePasswordAsync(member,changePassword.Name.ToString(), changePassword.Password);
                }
    
  • Linx 98 posts 258 karma points
    Mar 21, 2023 @ 16:08
    Linx
    0

    Is there anyway i could access memberManager through the Razor template or best to have this injected from a Controller level?

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 21, 2023 @ 16:11
    Huw Reddick
    1

    It would be best to use a controller, but you can inject it into a view

    @inject IMemberManager memberManager
    
  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 10:27
    Linx
    0

    Hi Huw

    I tried what you suggested using a controller but it didnt work as it did in previous editions of Umbraco. So i created a DocType MemberReset, with a template. In my project i create a new Controller folder and new controller called MemberResetController.

    I inherit it with RenderController (Umbraco 10).

    I create the Constructor as required for U 10 i.e. ILogger, ICompositeViewEngine etc etc.

    The Index method throws an error about same name.

    So i change the Index code to include override which allows me to view the page:

    public override IActionResult Index()
    {
     .....
     return View("~Views/MemberReset/Index.cshtml");
    }
    
    1. At this stage i add in MemberManager into the constructor, but i dont see any methods to find the member by email?

    2. Some threads suggest i cant add a parameters to this code as part of the Umbraco 10 so how could i pass in the email address from the template?

    Many thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 11:40
    Huw Reddick
    1

    Hi Linx,

    To get a member usinng their email you need to use the IMemberService,, so you should probably do something like below instead

    private readonly IMemberService _memberService;
    private readonly IMemberManager _manager;
    private readonly IPasswordHasher _hasher;
    public AuthenticationController(IMemberService memberService, IMemberManager manager, IPasswordHasher hasher)
    {
        _memberService = memberService;
        _manager = manager;
        _hasher = hasher;
    
    }
    

    You can then set the password using the below code

    // Check if the password adheres to the the password policy.
    IdentityResult validationResult = await _manager.ValidatePasswordAsync(model.NewPassword);
    if (validationResult.Succeeded)
    {
        // Save the password on the member.
        IMember member = _memberService.GetByKey(memberIdent);
        member.RawPasswordValue = _hasher.HashPassword(model.NewPassword);
        _memberService.Save(member);
    }
    
  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 12:29
    Linx
    0

    Thanks Huw, almost there, how are you passing in the model?

    Im using RenderController in my class

    public class MyCLass : RenderController
    

    and if i have a parameterised method (to pass my model) it tells me no overrideable method found?

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 12:54
    Huw Reddick
    0

    I'm using a Form which posts to a SurfaceController

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 13:02
    Huw Reddick
    1

    In my Forum package however I use an UmbRegisterController

    public class ForumMemberController : UmbRegisterController
    {
    
        private readonly ILogger _logger;
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IForumMailService _mailService;
        private readonly IMemberService _memberService;
        private readonly IMemberManager _memberManager;
        private readonly IUmbracoHelperAccessor _localizationService;
        private readonly IMemberSignInManager _memberSignInManager;
    
        public ForumMemberController(IMemberManager memberManager, IMemberService memberService, IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider, IMemberSignInManager memberSignInManager, IScopeProvider scopeProvider,ILogger<ForumMemberController> logger,IHttpContextAccessor httpContextAccessor,IForumMailService mailService,IUmbracoHelperAccessor localizationService) 
            : base(memberManager, memberService, umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider, memberSignInManager, scopeProvider)
        {
            _logger = logger;
            _httpContextAccessor = httpContextAccessor;
            _mailService = mailService;
            _memberService = memberService;
            _memberManager = memberManager;
            _localizationService = localizationService;
            _memberSignInManager = memberSignInManager;
        }
    
        [HttpPost]
        public async Task<IActionResult> HandleLoginAsync(LoginModel login)
        {
            if (ModelState.IsValid == false)
            {
                return CurrentUmbracoPage();
            }
    
            if (await _memberManager.ValidateCredentialsAsync(login.Username, login.Password))
            {
                var result = await _memberSignInManager.PasswordSignInAsync(login.Username, login.Password, login.RememberMe, true);
                if (result.Succeeded)
                {
                    if (Url.IsLocalUrl(login.RedirectUrl))
                    {
                        return Redirect(login.RedirectUrl);
                    }
    
                    return RedirectToCurrentUmbracoPage();
                }
    
            }
            else
            {
                ModelState.AddModelError(string.Empty, "The username or password provided is incorrect.");
            }
            // If there is a specified path to redirect to then use it.
    
            return CurrentUmbracoPage();
        }
    
        [HttpPost]
        public async Task<IActionResult> RegisterMeAsync([Bind(Prefix = "registerModel")] Umbraco.Cms.Web.Website.Models.RegisterModel newmember)
        {
    
            if (ModelState.IsValid == false)
            {
                return CurrentUmbracoPage();
            }
            var usernamecheck = _memberService.GetByUsername(newmember.Username);
            if (usernamecheck != null)
            {
                ModelState.AddModelError("Registration","The username is already in use, please use another");
                return CurrentUmbracoPage();
            }
    
            var identityUser = MemberIdentityUser.CreateNew(newmember.Username, newmember.Email,"forumMember", isApproved: false, newmember.Name);
            IdentityResult identityResult = await _memberManager.CreateAsync(
                identityUser,
                newmember.Password);
            var member = _memberService.GetByEmail(identityUser.Email);
    
            string resetGuid = null;
            if (member != null)
            {
                resetGuid = ForumHelper.GenerateUniqueCode(16);
                member.SetValue("resetGuid",resetGuid);
                //member.IsApproved = false;
                foreach (MemberPropertyModel property in newmember.MemberProperties.Where(p => p.Value != null)
                    .Where(property => member.Properties.Contains(property.Alias)))
                {
                    member.Properties[property.Alias]?.SetValue(property.Value);
                }
            }
    
            _memberService.Save(member);
            try
            {
                var umbracoHelper = _httpContextAccessor.HttpContext.RequestServices.GetRequiredService<UmbracoHelper>();
    
                TempData["FormSuccess"] = await _mailService.SendVerifyAccount(member.Email,resetGuid);;
            }
            catch (Exception e)
            {
                _logger.LogError(e,"Problem sending Validation email");
                throw;
            }
    
    
            // If there is a specified path to redirect to then use it.
            if (string.IsNullOrWhiteSpace(newmember.RedirectUrl) == false)
            {
                return Redirect(newmember.RedirectUrl!);
            }
            return CurrentUmbracoPage();
        }
    
        [HttpPost]
        public async Task<IActionResult> PasswordReset([Bind(Prefix = "registerModel")]RegisterModel changePassword,string token)
        {
            //do the passwords match
            if (changePassword.Password != changePassword.ConfirmPassword)
            {
                TempData["ValidationError"] = "Passwords do not match!";
                return CurrentUmbracoPage();
            }
            try
            {
                var changePasswordResult =
                    await _memberManager.ChangePasswordWithResetAsync(changePassword.Name.ToString(), token, changePassword.Password);
                if (changePasswordResult.Succeeded)
                {
                    TempData["ValidationSuccess"] = "success";
                }
                else
                {
                    foreach (var identityError in changePasswordResult.Errors)
                    {
                        TempData["ValidationError"] += identityError.Description;
                    }
                }
    
            }
            catch (Exception e)
            {
                TempData["ValidationError"] = e.Message;
            }
    
    
            return CurrentUmbracoPage();
        }
    }
    

    I have a form in a partialview

        @inject MemberModelBuilderFactory memberModelBuilderFactory
    @{
    
        var registerModel = memberModelBuilderFactory
            .CreateRegisterModel()
            .WithMemberTypeAlias("forumMember")
            .WithRedirectUrl(null)
            .WithCustomProperties(true)
            .Build();
    
        registerModel.Name = Model.MemberId;
    }
    <p>&nbsp;</p>
    @using (Html.BeginUmbracoForm<ForumMemberController>("PasswordReset", null, new { id = "reset-form-id" }, FormMethod.Post))
        {
            <hr />
            <div class="form-group">
    
    
                <div class="mb-3">
                    <label asp-for="@registerModel.Password" class="form-label"></label>
                    <input asp-for="@registerModel.Password" class="form-control" autocomplete="new-password" aria-required="true" />
                    <span asp-validation-for="@registerModel.Password" class="form-text text-danger"></span>
                </div>
                <div class="mb-3">
                    <label asp-for="@registerModel.ConfirmPassword" class="form-label"></label>
                    <input asp-for="@registerModel.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" />
                    <span asp-validation-for="@registerModel.ConfirmPassword" class="form-text text-danger"></span>
                </div>
                <div class="mb-3">
                    <input asp-for="@registerModel.Name" class="form-control" aria-required="true" type="hidden" />
                    <input asp-for="@registerModel.Email" class="form-control" autocomplete="username" type="hidden" />
                </div>
                <input type="hidden" name="Id" value="@Model.MemberId" />
                <input type="hidden" name="token" value="@Model.ResetToken" />
            </div>
            <div asp-validation-summary="All" class="text-danger"></div>
            <div class="form-group"> <button type="submit" class="btn btn-danger" id="register-submit" >Save</button></div>
        }
    
  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 13:36
    Linx
    0

    Great, taking a look but i noticed i dont have access to MemberId and ResetToken. Are these needed or have you extended the existing model (think thats RegisterModel)?

    When someone arrives to this page, how do i know what member i am resetting the password for?

    Thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 13:46
    Huw Reddick
    1

    They are needed to use ChangePasswordWithResetAsync method, but not necesary if you just use the changePassword.

    In my flow when a member wants to change a password they are sent an email with a link that contains the token, clicking on the link then directs them to the change password form and populates the token.

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 14:01
    Linx
    0

    So i can send see the token being passed in if i send a request with ?token=1234 but tried using the GUID for an existing member and that resulted in Object not set to an instance on ChangePasswordWithResetAsync (the Name field is empty, though i noticed you are probably populating this somehow on the cshtml page possibly with a valid token), so how should i be populating this token if its not the Member GUID?

    BTW for now i have removed the two fields above for now but i have a feeling once i understand how the token is achieved i may have to re-introduce the token field.

    Thanks again for your help (:thumbs-up)

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 14:07
    Huw Reddick
    1

    you can generate the token using

            var member = _memberService.GetByEmail(model.EmailAddress);
            var memberIdentity = _memberManager.FindByIdAsync(member.Id.ToString()).Result;
            // we found a user with that email ....
            var token = _memberManager.GeneratePasswordResetTokenAsync(memberIdentity).Result;
    
  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 14:03
    Huw Reddick
    1

    You could just use a form like this

    @using (Html.BeginUmbracoForm<ForumMemberController>("ChangePassword", FormMethod.Post))
    {
        <h4>Change your Password.</h4>
        <hr />
        <div class="form-group">
            <div class="mb-3">
                <label asp-for="@Model.NewPassword" class="form-label">New Password</label>
                <input asp-for="@Model.NewPassword" class="form-control" required="" />
                <span asp-validation-for="@Model.NewPassword" class="form-text text-danger"></span>
            </div>
            <div class="mb-3">
                <label for="@Model.OldPassword" class="form-label">Current Password</label>
                <input asp-for="@Model.OldPassword" class="form-control" required="" />
                <span asp-validation-for="@Model.OldPassword" class="form-text text-danger"></span>
            </div>
            <input type="hidden" name="Id" value="@_memberManager.GetCurrentMemberAsync().Result.Id" />
        </div>
        <div class="form-group"> <button type="submit" class="btn btn-danger">Save</button></div>
    }
    

    and a method like

    [HttpPost]
    public async Task<IActionResult> ChangePassword(ChangingPasswordModel model)
    {
    
        try
        {
            IMember member = _memberService.GetById(model.Id);
            member.RawPasswordValue = _hasher.HashPassword(model.NewPassword);
            _memberService.Save(member);
    
        }
        catch (Exception e)
        {
            TempData["ValidationError"] = e.Message;
        }
    
    
        return CurrentUmbracoPage();
    }
    
  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 14:35
    Linx
    0

    Ive created an instance of _hasher as IPasswordHasher.

    For the form im still not sure what i may have missed. NewPassword, OldPassword dont exist even though i have @using Umbraco.Cms.Core.Models and for _memberManager, ive introduced

    @inject MemberManager _memberManager
    @{
    }
    

    which seems to have resolved the highlighted error but im not sure at this stage if this is ok or not

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 14:57
    Huw Reddick
    1

    They aree part of the ChangingPasswordModel. MemberController is an implementation of UmbRegisterController

    Change password form partialview

    @model Umbraco.Cms.Core.Models.ChangingPasswordModel
    @using Umbraco.Extensions
    
    <p>&nbsp;</p>
    @using (Html.BeginUmbracoForm<MemberController>("ChangePassword", FormMethod.Post))
    {
        <h4>Change your Password.</h4>
        <hr />
        <div class="form-group">
            <div class="mb-3">
                <label for="@Model.OldPassword" class="form-label">Current Password</label>
                <input asp-for="@Model.OldPassword" class="form-control" required="" />
                <span asp-validation-for="@Model.OldPassword" class="form-text text-danger"></span>
            </div>        
            <div class="mb-3">
                <label asp-for="@Model.NewPassword" class="form-label">New Password</label>
                <input asp-for="@Model.NewPassword" class="form-control" required="" />
                <span asp-validation-for="@Model.NewPassword" class="form-text text-danger"></span>
            </div>
    
        </div>
        <div class="form-group"> <button type="submit" class="btn btn-danger">Save</button></div>
    }
    

    in the MemberController the ChangePassword method is

    [HttpPost]
    public async Task<IActionResult> ChangePassword(ChangingPasswordModel model)
    {
        var passwordvalid = _memberManager.ValidatePasswordAsync(model.NewPassword).Result;
        if (passwordvalid.Succeeded)
        {
            try
            {
                var member = _memberManager.GetCurrentMemberAsync().Result;
                var changePasswordResult =
                    await _memberManager.ChangePasswordAsync(member, model.OldPassword, model.NewPassword);
                if (changePasswordResult.Succeeded)
                {
                    TempData["ValidationSuccess"] = "success";
                }
                else
                {
                    foreach (var identityError in changePasswordResult.Errors)
                    {
                        TempData["ValidationError"] += identityError.Description;
                    }
                }
    
            }
            catch (Exception e)
            {
                TempData["ValidationError"] = e.Message;
            }
        }
        else
        {
            TempData["ValidationError"] = passwordvalid.Errors.ToString();
        }
    
        return CurrentUmbracoPage();
    }
    
  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 15:11
    Linx
    0

    Ok can give this a go.... So are you saying i should continue to use UmbRegisterController like before

    public class MyClassController : UmbRegisterController 
    

    Finally, BeginUmbracoForm(MemberController) (on the form) i would imagine youre not using the BackOffice Controller (same name) so i would change this to BeginUmbracoForm(MyClassController) - i ask as im currently seeing the error The Model item passed into teh ViewDataDictionary is of Umbraco.Cms.Core.Models.ContentModel but rrquires Umbraco.Cms.Core.Models.ChangingPasswordModel

    Thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 15:16
    Huw Reddick
    0

    can you show me the full code for your view and I will try to explain what you need to do (my form is in a partial view so does not inherit from an umbraco viewpage.

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 15:20
    Linx
    0

    Here my current code

    public class CustomMemberController : UmbRegisterController
            {
                   private readonly ILogger _logger;
                   private readonly IHttpContextAccessor _httpContextAccessor;
                   private readonly IMemberService _memberService;
                   private readonly IMemberManager _memberManager;
                   private readonly IUmbracoHelperAccessor _localizationService;
                   private readonly IMemberSignInManager _memberSignInManager;
                   private readonly IPasswordHasher _hasher;
                   public CustomMemberController (
                           IMemberManager memberManager, 
                           IMemberService memberService, 
                           IUmbracoContextAccessor umbracoContextAccessor, 
                           IUmbracoDatabaseFactory databaseFactory, 
                           ServiceContext services, AppCaches appCaches, 
                           IProfilingLogger profilingLogger, 
                           IPublishedUrlProvider publishedUrlProvider, 
                           IMemberSignInManager memberSignInManager, 
                           IScopeProvider scopeProvider, 
                           ILogger<ResetPasswordController> logger, 
                           IHttpContextAccessor httpContextAccessor, 
                           IUmbracoHelperAccessor localizationService,
                IPasswordHasher hasher)
             : base(memberManager, memberService, umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider, memberSignInManager, scopeProvider)
                   {
                           _logger = logger;
                           _httpContextAccessor = httpContextAccessor;
                           _memberService = memberService;
                           _memberManager = memberManager;
                           _localizationService = localizationService;
                           _memberSignInManager = memberSignInManager;
                           _hasher = hasher;
                   }
    
    [HttpPost]
            public async Task<IActionResult> ChangePassword(ChangingPasswordModel model)
            {
                var passwordvalid = _memberManager.ValidatePasswordAsync(model.NewPassword).Result;
                if (passwordvalid.Succeeded)
                {
                    try
                    {
                        var member = _memberManager.GetCurrentMemberAsync().Result;
                        var changePasswordResult =
                            await _memberManager.ChangePasswordAsync(member, model.OldPassword, model.NewPassword);
                        if (changePasswordResult.Succeeded)
                        {
                            TempData["ValidationSuccess"] = "success";
                        }
                        else
                        {
                            foreach (var identityError in changePasswordResult.Errors)
                            {
                                TempData["ValidationError"] += identityError.Description;
                            }
                        }
    
                    }
                    catch (Exception e)
                    {
                        TempData["ValidationError"] = e.Message;
                    }
                }
                else
                {
                    TempData["ValidationError"] = passwordvalid.Errors.ToString();
                }
    
                return CurrentUmbracoPage();
            }
    }
    

    Needs some tidying but i can take care of that once i have the minimal functionality working :-)

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 15:22
    Huw Reddick
    0

    I also need to see the code for your view where you are using the form that posts to the controller

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 15:24
    Linx
    0
    @model Umbraco.Cms.Core.Models.ChangingPasswordModel
    @using TestProject.Core.Controllers;
    @using Umbraco.Extensions
    
    @using (Html.BeginUmbracoForm<CustomMemberController>("ChangePassword", FormMethod.Post))
    {
        <h4>Change your Password.</h4>
        <hr />
        <div class="form-group">
            <div class="mb-3">
                <label for="@Model.OldPassword" class="form-label">Current Password</label>
                <input asp-for="@Model.OldPassword" class="form-control" required=" />
                <span asp-validation-for="@Model.OldPassword class="form-text text-danger"></span>
            </div>
            <div class="mb-3">
                <label asp-for="@Model.NewPassword" class="form-label">New Password</label>
                <input asp-for="@Model.NewPassword" class="form-control" required=" />
                <span asp-validation-for="@Model.NewPassword class="form-text text-danger"></span>
            </div>
    
        </div>
        <div class="form-group"> <button type="submit" class="btn btn-danger">Save</button></div>
    }
    
  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 15:30
    Huw Reddick
    0

    Is this the whole of your view? That is just a copy of my snippet, how are you displaying this in a page exactly? say for example your home or another page from your site content.

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 15:34
    Huw Reddick
    1

    in one of your pages you should load that snippet as a partial view

    @await Html.PartialAsync("_ChangePassword",new ChangingPasswordModel())
    

    so save the snippet in the Views\Partials folder as _ChangePassword.cshtml and use the code above to display the form in your page

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 15:50
    Linx
    0

    Currently im displaying a standard page in a single template. In this template i have the snippet to ensure all works before making further changes.

    I navigate to localhost://test and the page displays the snippet code.

    Let me tweak it and hopefully all should click into place :-)

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 16:00
    Huw Reddick
    1

    if the snippet is directly in your page then that is why it is complaining about models probably, save the snippet to a new file as I suggested and include it using the

    @await Html.PartialAsync("_ChangePassword",new ChangingPasswordModel())
    

    That should take care of the model issues

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 16:15
    Linx
    0

    Looks much better. Thanks for your help.

    I noticed the ChangingPasswordModel has an ID property, so does this mean i could use the code you listed above to instantiate the memberService and get the user by email passing in the ID or should i set up the email with the token that is sent and use that to change the password for the member?

    Thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 16:22
    Huw Reddick
    100

    you would need to pass the ID with the form, it will be null by default.

    TBH the changepassword kind of assumes that the member is already logged in, so the Chnagepassword method uses GetCurrentMemberAsync() to get the member who is changing there password.

    It really depends what you are actually attempting to do.

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 16:32
    Linx
    0

    I like the idea you have to generate a token in order to initiate the reset password, so i would like to send the email when a user enters their email address for forgetting their password (I can do this and the token code is above just to give you the entire process).

    When they click the link i would like the account to be found (lets say using the snippet above but just the New Password field) and the old password would not be required as theyve forgotten it.

    My research leaves me to believe it might be the ID listed against the member in Umbraco but i tried that and it didnt work. If i need to get by email address then i think i have to use memberService but continue to use _memberManager.ChangePassword to change the password? If im on the right track and understood this correctly?

    Thx

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 22, 2023 @ 16:36
    Huw Reddick
    0

    OK, that is generally what I do, TBH the member enters their email addres and submit a form, that then sends them an email with the link and token, when they click on the link they get redirected to another form where they enter the new password, the controller then uses the token to set the new password.

    If you can wait until tomorrow I can post the code I use, just signing off for the day I'm afraid :)

  • Linx 98 posts 258 karma points
    Mar 22, 2023 @ 16:40
    Linx
    0

    Sure no problem and thanks again for your help

  • Linx 98 posts 258 karma points
    Mar 23, 2023 @ 10:43
    Linx
    0

    Hi

    Ive got a little further in that i can generate the token and reset the password if i have values hardcoded in my code (to ensure all is working).

    Since i am using ChangeModelPassword which has Id, oldPssword and NewPassword, i just need to change the password based on the user.

    I use this amended code with hardcoded values (which as i mentioned does work)

     var passwordvalid = _memberManager.ValidatePasswordAsync(model.NewPassword).Result;
                if (passwordvalid.Succeeded)
                {
                    try
                    {
                      string token = "1234";
                        var member = _memberManager.FindByEmailAsync("[email protected]").Result;
                        var changePasswordResult =
                            await _memberManager.ResetPasswordAsync(member, token, model.NewPassword);
    

    So do i need to create a new model or is there a cleaner way to achieve this, assuming if the above is correct once the hardcoded values have been converted?

    Thanks

  • Huw Reddick 1736 posts 6075 karma points MVP c-trib
    Mar 23, 2023 @ 11:52
    Huw Reddick
    1

    Hi Linx,

    apologies for the delay, I have been in meetings most of the morning. I put together a quick blog post last night which should help.

    https://umbraco.themediawizards.co.uk/the-grimoire/members-forgot-password/

  • Linx 98 posts 258 karma points
    Mar 23, 2023 @ 12:40
    Linx
    0

    Thanks will check this out and report back. Thank you

Please Sign in or register to post replies

Write your reply to:

Draft