Change User Validations ASP.Net Identity2

By | April 5, 2015

In asp.Net identity 2 in order to restrict user information implemented some validation properties that’s are:
follows:

AllowOnlyAlphanumericUserNames : If this property set to “false” then ASP.Net Identity will not allow user to enter user name in alpha numeric form. Otherwise it will allow users to enter user name in alpha numeric form.

RequireUniqueEmail : If this property set to “true” then ASP.Net Identity will not allow users to enter single email address multiple registrations. Otherwise it will allow users to enter same email for multiple registrations.

By default both property set as follows:

// Configure validation logic for usernames
manager.UserValidator = new UserValidator(manager)
{
    AllowOnlyAlphanumericUserNames = false,
    RequireUniqueEmail = true
};

Above validations are defined inside Create method of IdentityConfig.cs. Create is a static factory method for “ApplicationUserManager”.

If anyone want to cange one or both validation then he/she can change the value of above properties as follows:

@. Allow alphanumeric user name for registration:

manager.UserValidator = new UserValidator(manager)
{
    AllowOnlyAlphanumericUserNames = true,
    RequireUniqueEmail = true
};

@. Allow to use same email address for multiple registration:

manager.UserValidator = new UserValidator(manager)
{
    AllowOnlyAlphanumericUserNames = false,
    RequireUniqueEmail = false
};

@. Allow alpha numeric user name for registration and allow to use same email address for multiple registrations:

manager.UserValidator = new UserValidator(manager)
{
    AllowOnlyAlphanumericUserNames = true,
    RequireUniqueEmail = false
};

Hope above information will help us.
Happy coding.

532 Total Views 1 Views Today
Md. Mojammel Haque

CSM, CSPO, CSD, CSP-SM, CSP-PO (ScrumAlliance.org)
Certification Profile Link-
https://www.scrumalliance.org/community/profile/mhaque13

Currently working as Lead Team (Application Architecture) at Raven Systems Ltd. Passion for software development especially agile practices such as TDD with in depth knowledge of Object Oriented Programming, SOLID Principles, Gang of Four Design Patterns, Some Enterprise Application Architectural Patterns. Over 8 years of software development experience ASP.NET. Has the ability to understand and transform complex business requirements into software ensuring applications are delivered on time. Also experience in non Microsoft .NET technologies such as Dapper.Net, Git, Structure Map & Angular, Bootstrap, HTML-5, CSS-3 etc.

Category: Uncategorized
Md. Mojammel Haque

About Md. Mojammel Haque

CSM, CSPO, CSD, CSP-SM, CSP-PO (ScrumAlliance.org) Certification Profile Link- https://www.scrumalliance.org/community/profile/mhaque13 Currently working as Lead Team (Application Architecture) at Raven Systems Ltd. Passion for software development especially agile practices such as TDD with in depth knowledge of Object Oriented Programming, SOLID Principles, Gang of Four Design Patterns, Some Enterprise Application Architectural Patterns. Over 8 years of software development experience ASP.NET. Has the ability to understand and transform complex business requirements into software ensuring applications are delivered on time. Also experience in non Microsoft .NET technologies such as Dapper.Net, Git, Structure Map & Angular, Bootstrap, HTML-5, CSS-3 etc.

Leave a Reply

Your email address will not be published. Required fields are marked *