A client wants to use emails as usernames. The reason is that this multisite solution has users with different email domains so there's a chance that stripping @domain.com will cause a duplicate username to be created by an automated process. I found this blog but I started getting an error saying that the email I was using was invalid when trying to create a user with Sitecore.Security.Accounts.User.Create(string userName, string password). The error was as follows:

Exception thrown: 'System.Web.Security.MembershipCreateUserException' in System.Web.dll. The E-mail supplied is invalid.

at System.Web.Security.Membership.CreateUser(String username, String password, String email) at Sitecore.Security.Accounts.User.Create(String userName, String password) at CroweHorwath.SiteGenerator.Generic.Services.BaseSiteGeneratorService.CreateUser(UserInformation userInformation, INotifySiteGeneratorProgress progress) in C:\Projects\Crowe\Code\CroweHorwath\CroweHorwath.SiteGenerator.Generic\Services\BaseSiteGeneratorService.cs:line 358

Is there a different method that I should use instead of Sitecore.Security.Accounts.User.Create(string userName, string password)?


Did you try by adding "AccountNameValidation" regex? here is a KB article - https://kb.sitecore.net/articles/259229

you can try by changing value to the simple regex expression or expression for the email.

  • The blog post I linked to referenced that exact setting and set it to be basically a wildcard. Wouldn't the error I am receiving say there is an issue with the username if that was the issue too? – Teeknow Jul 31 '17 at 15:38

This is my current work around for the error. I changed the attribute that was mentioned in the post to be false again (requiresUniqueEmail) since username uniqueness should handle my use case. If someone has a more appropriate method to use other than Sitecore's user creation method I mentioned in my question that can get around the issue I was seeing with that attribute set I would like to know it (and would accept that as the more proper answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.