I am trying to programmatically create a user but I'm running into problems hashing the password. I have no idea if it's Umbraco or standard .NET core that should handle this.
My code looks like this:
private void CreateUserIfNotExist(string email, string password, string? name)
{
var user = _userService.GetByEmail(email);
if (user != null)
{
return;
}
var newUser = _userService.CreateUserWithIdentity(name ?? email, email);
var userGroup = _userService.GetUserGroupByAlias("editors") as IReadOnlyUserGroup;
if (userGroup != null)
{
newUser.AddGroup(userGroup);
newUser.RawPasswordValue = ???? // how to hash password?
_userService.Save(newUser);
}
}
How can I figure out the RawPasswordValue? I've tried 5 different ways of dependency inject a password hasher, but I can't find a way to type it to <IUser> which is what CreateUserWithIdentity returns.
The documentation has a page that brings up my hope:
https://docs.umbraco.com/umbraco-cms/reference/management/services/userservice/create-a-new-user
But it has no example shown at all, broken documentation perhaps?
This will show you how to create a new user using the UserService in Umbraco.