Copied to clipboard

Flag this post as spam?

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


  • Josip 195 posts 662 karma points c-trib
    Mar 25, 2020 @ 14:36
    Josip
    0

    Programaticaly change password

    How can i change members password?

    When I try this:

    if (System.Web.Security.Membership.ValidateUser(username, model.OldPassword))
            {
                var memberService = Services.MemberService;
                var member = memberService.GetByUsername(username);
    
                memberService.SavePassword(member, model.NewPassword);
                memberService.Save(member);
    
                return Redirect("/");
            }
    

    I get this error: This provider does not support manually changing the password

    I know that i can set allowManuallyChangingPassword="true" on the UmbracoMembershipProvider, but is there any other way ?

    BR

  • Harikrishna Parmar 43 posts 262 karma points c-trib
    Mar 26, 2020 @ 16:33
    Harikrishna Parmar
    0

    Please try this code block :

         var user = Members.CurrentUserName;
         if (Members.GetByUsername(user) != null)
         {
             var services = Current.Services.MemberService;
             var servicesResult = services.GetByUsername(user);
             services.SavePassword(servicesResult, model.Password);
         }
    

    or you can also try :

        if (Members.GetByEmail(model.Email) != null)
        {
               var services = Current.Services.MemberService;
               var servicesResult = services.GetByEmail(model.Email);
               services.SavePassword(servicesResult, model.Password);            
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft