Copied to clipboard

Flag this post as spam?

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


  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 14:11
    Tom Bruce
    0

    Identity - Password reset for Umbraco members

    Hi folks, I'm trying to allow users to reset their passwords, does anyone have code snippet I could look at?

    I have been trying to reset the password with the following code;

    var m = Membership.GetUser();
    
            m.ResetPassword(model.Password);
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 14:19
    Alex Skrypnyk
    0

    Hi Tom

    You can use MemberService SavePassword(IMember member, "newSecretPass1234") method as well:

    https://our.umbraco.org/documentation/reference/management/services/memberservice#savepassword-imember-member-newsecretpass1234

    Thanks,

    Alex

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 14:23
    Tom Bruce
    0

    Hi Alex, is this for the Identity framework?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 14:24
    Alex Skrypnyk
    0

    It's general for Umbraco members.

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 14:27
    Tom Bruce
    0

    Hi Alex, Umbraco 7 is now is the Identity framework for members, I think..

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 14:29
    Tom Bruce
    0

    How would you implement

    .SavePassword(IMember member, "newSecretPass1234");

    can you provide example...

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 14:45
    Tom Bruce
    0

    I'm trying the following snippet

      var memberService = ApplicationContext.Current.Services.MemberService;
    
            var member = memberService.GetById(AppHelper.GetCurrentUserId());
    
            memberService.SavePassword(member, model.Password);
    

    Receiving error;

    AppHelper does not exist in current context???

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 15:10
    Alex Skrypnyk
    0

    Tom, what is "AppHelper.GetCurrentUserId()"?

    Are you working with users or members?

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 15:12
    Tom Bruce
    0

    I'm working with member. I'm trying the following code, member come back null.

      private int GetCurrentUserId()
        {
            var userService = ApplicationContext.Current.Services.UserService;
            return userService.GetByUsername(HttpContext.Current.User.Identity.Name).Id;
        }
    
        public void EditYourLoginDetails(ApplicationViewModel model)
        {
            //var m = Membership.GetUser();
    
            var password = "password123";
    
            var memberService = ApplicationContext.Current.Services.MemberService;
    
            var member = memberService.GetById(GetCurrentUserId());
    
            ApplicationContext.Current.Services.MemberService.SavePassword(member, password);
        }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 15:21
    Alex Skrypnyk
    1

    Tom, in first method you work woth Users in second with members :)

    Member is an authenticated customer for front end site.

    User is an authenticated user for Umbraco backend.

    Thanks,

    Alex

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 15:23
    Tom Bruce
    0

    Thanks Alex, how do I reset a member password?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 15:29
    Alex Skrypnyk
    0

    Tom, try this code:

            var password = "password123";
    
            var memberService = ApplicationContext.Current.Services.MemberService;
    
            var membersipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
    
            var member = memberService.GetByUsername(membersipHelper.CurrentUserName);
    
            ApplicationContext.Current.Services.MemberService.SavePassword(member, password);
    
  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 15:30
    Tom Bruce
    0

    Hi Alex, I tried your code, error at the last line.....

    This provider does not support manually changing the password

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 15:55
    Alex Skrypnyk
    101

    Tom, please, check this flag "allowManuallyChangingPassword"="false" in your web.config file, read more about it here -

    https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/85722-problem-updating-members-password-using-umbraco-version-761#comment-271567

    "allowManuallyChangingPassword" should be true

    Thanks,

    Alex

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 16:47
    Tom Bruce
    0

    Thanks Alex, much appreciated.

  • Tom Bruce 122 posts 506 karma points
    Sep 19, 2017 @ 17:15
    Tom Bruce
    0

    Alex, I have a textbox that users can type in their new passwords. How do you apply the password validation rules to the textbox i.e. password must be minimum of 10 charters etc.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 19, 2017 @ 19:03
    Alex Skrypnyk
    1

    Tom, are you using mvc razor coding?

    Maybe some js validation?

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft