Copied to clipboard

Flag this post as spam?

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

  • Miguel Lopez 11 posts 93 karma points
    Jun 05, 2019 @ 09:46
    Miguel Lopez

    Programmatically create user with password in V8

    I am trying to create a user programmatically with a given password in V8. The code is as follows, with the two options I have tested with no luck:

    var user = userService.CreateUserWithIdentity(email, email); 
    user.Name = name;
    user.RawPasswordValue = password;


    var user = userService.CreateWithIdentity(email, email, password, "guest", true);
    user.Name = name;

    None of these methods is saving the right password though, as it is not hashed when saved in the DB and the user cannot log in then. In V7 the userService had a method like userService.SavePassword(user,password), but I cannot seem to find it anymore in V8.


  • Tom Madden 252 posts 454 karma points MVP 3x c-trib
    Jun 20, 2019 @ 09:10
    Tom Madden


    I believe SavePassword is now renamed as ChangePassword



  • Miguel Lopez 11 posts 93 karma points
    Jun 21, 2019 @ 09:32
    Miguel Lopez

    Thanks Tom,

    it seems the UserService doesn't have any of those methods, either ChangePassword or SavePassword.

  • Jun 21, 2019 @ 11:06
    Abuabdellah | Biker | Umbracian | Freelancer |

    I found Umbraco V8 using ChangePasswordWithIdentityAsync when you edit user profile from the backoffice.

    I suggest to see the issue mentioned about this subject.

  • George Phillipson 108 posts 286 karma points
    Jun 16, 2020 @ 15:28
    George Phillipson

    I know this is an old post, but this is how I do it.

    var memberDetails = memberService.CreateMemberWithIdentity(model.Username, model.Email, $"{model.FirstName} {model.LastName}", "member");
                        memberDetails.SetValue("firstName", model.FirstName);
                        memberDetails.SetValue("lastName", model.LastName);
                        memberDetails.SetValue("address", model.Address);
                        memberDetails.SetValue("city", model.City);
                        memberDetails.SetValue("county", model.County);
                        memberDetails.SetValue("postCode", model.PostCode);
                        memberDetails.SetValue("contactNumber", model.ContactNumber);
                        memberDetails.IsApproved = false;//Change to true if you want to allow the member instant access, or false if they need to verify email etc before they can login
                        memberService.AssignRole(memberId: memberDetails.Id, roleName: "Member"); // I always assign the default role
                        memberService.SavePassword(memberDetails, model.Password);

    And don't forget to change 'allowManuallyChangingPassword' in web.config to true.

    I also found in two projects that the members could not create an account, turned out that these this setting minRequiredPasswordLength="10" was overriding my custom password length. Why it only happened on two websites I don't know; I never had time to investigate due to time constraints.

    Hope it helps

Please Sign in or register to post replies

Write your reply to: