Monday, December 27, 2010

Disable Sitecore User Account on Creation

When Creating a new User in code via the CreateUserWizard or simply by calling Sitecore.Security.Account.User.Create() the user is approved by default.
To alter this behavior you will need to get the user and update the IsApproved field.

If you are simply using Sitecore.Security.Account.User.Create() then you just need to do the following:

// Create a new user in the system
newUser = User.Create(userName, password);

// Since we just created the user they should not be approved yet.
MembershipUser user = GetMembershipUserByUserName(userName);
user.IsApproved = false;
Membership.UpdateUser(user);