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;
userService.Save(user);
or:
var user = userService.CreateWithIdentity(email, email, password, "guest", true);
user.Name = name;
userService.Save(user);
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.
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);
memberService.Save(memberDetails);
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.
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:
or:
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.
Thanks.
Hi,
I believe SavePassword is now renamed as ChangePassword
regards
t
Thanks Tom,
it seems the UserService doesn't have any of those methods, either ChangePassword or SavePassword.
I found Umbraco V8 using
ChangePasswordWithIdentityAsync
when you edit user profile from the backoffice.I suggest to see the issue mentioned about this subject.
I know this is an old post, but this is how I do it.
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
is working on a reply...