Copied to clipboard

Flag this post as spam?

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


  • Mikhail 3 posts 73 karma points
    16 days ago
    Mikhail
    0

    Change members password programmatically

    I'm new in Umbraco. I need to implement changing members password.

    I have the endpoint:

    public BaseResponse Put(UpdatePasswordModel model)
        {
            var response = new BaseResponse();
    
            if (!ModelState.IsValid)
            {
                response.Code = ErrorCode.WrongUsernameOrPassword;
                response.Message = "Wrong username or password!";
                return response;
            }
    
            var member = _memberService.GetByUsername(model.UserName);
    
            if (member == null)
            {
                response.Code = ErrorCode.MemberNotFound;
                response.Message = $"Member {model.UserName} not found";
    
                return response;
            }
    
            var passwordModel = new ChangingPasswordModel { NewPassword = model.NewPassword, OldPassword = model.OldPassword };
            _membershipHelper.ChangePassword(model.UserName, passwordModel, "UmbracoMembershipProvider");
    
            response.Code = ErrorCode.Success;
    
            return response;
        }
    

    UpdatePasswordModel contains UserName, OldPassword, NewPassword.

    Has ChangePassword metdod some validation for old and new passwords? What is the best way to change members password?

  • Alex Skrypnyk 5365 posts 19802 karma points MVP 3x admin c-trib
    6 days ago
    Alex Skrypnyk
    0

    Hi Mikhail

    There is a param in Umbraco Security Settings that can specify a regular expression for a password - "passwordStrengthRegularExpression"

    https://our.umbraco.com/Documentation/Reference/Security/Security-settings/

    But I'm not sure that it will work if you change a password through the code.

    Thanks,

    Alex

  • Alex Skrypnyk 5365 posts 19802 karma points MVP 3x admin c-trib
    1 day ago
    Alex Skrypnyk
    0

    Hi Mikhail

    Let us know if you found a solution.

    Thanks, Alex

Please Sign in or register to post replies

Write your reply to:

Draft