But these users cannot login into Umbraco CMS then. I have checked the umbracoUser table and I see that passwords for users created manually (from UI) are encrypted/hashed. Passwords for the users I create from C# code are stored in clear form and that is why they cannot login I guess. What else should I do to create a user?
You'll probably want to use the Users Membership provider to create the users, as this already contains the logic to hash the passwords for you, so something like:
PS, You'll notice I get the provider by name, as if you look in the web.config, you'll see the Members membership provider is the default, so we need to specifically say we want to use the Users provider
It looks like you are right. Looking at the source, it does look like it just saves the value straight to the DB, so yes, you will need to call EncodePassword before hand. It might be worth checking the source for the creat user dialog to see how Umbraco are doing it.
It would certainly make sence though that this was part of the CreateUser method of the Membership provider though, so might be worth checking codeplex to see if it has been raised as an issue, and if not, add it.
How do I create users from c# code?
I can create users like this:
umbraco.BusinessLogic.User.MakeNew("name", "login", "password", myUserType);
But these users cannot login into Umbraco CMS then. I have checked the umbracoUser table and I see that passwords for users created manually (from UI) are encrypted/hashed. Passwords for the users I create from C# code are stored in clear form and that is why they cannot login I guess. What else should I do to create a user?
Hi Alex,
You'll probably want to use the Users Membership provider to create the users, as this already contains the logic to hash the passwords for you, so something like:
Many thanks
Matt
PS, You'll notice I get the provider by name, as if you look in the web.config, you'll see the Members membership provider is the default, so we need to specifically say we want to use the Users provider
It does not work either. Internally it calls User.MakeNew(username, username, password, userType);
Hi Alex,
It looks like you are right. Looking at the source, it does look like it just saves the value straight to the DB, so yes, you will need to call EncodePassword before hand. It might be worth checking the source for the creat user dialog to see how Umbraco are doing it.
It would certainly make sence though that this was part of the CreateUser method of the Membership provider though, so might be worth checking codeplex to see if it has been raised as an issue, and if not, add it.
Matt
is working on a reply...