How do you change (email, password) to (username,password) with ASP.net Identity

asp.net-identity asp.net-mvc asp.net-mvc-5 entity-framework entity-framework-6

Question

I tough this would have been trivial and provided in the MVC template, but actually creating ASP.NET project > MVC 5/EF6 with Individual Account is giving me an email, password credentials combination. Strange considering the Getting Started of Identity shows username, password combination.

enter image description here

While many seems to want to do the other way around I actually want to convert that default (email, password) behavior to a more basic (username, password). But that seems to require manual modification to the controller, startup, layout and model. Actually what exactly do I have to change to achieve this?

Note that my setup is the basic Visual Studio 2013 Community Edition with nothing more.

1
0
2/3/2015 11:04:38 PM

Popular Answer

A hint, This is to change from username to email. In your account controller

public AccountController(UserManager<User> userManager)
{
    UserManager = userManager;

    //Login using Email instead of Username, disable UserName validation
    var userValidator = UserManager.UserValidator as UserValidator<User>;
    if (userValidator != null) userValidator.AllowOnlyAlphanumericUserNames = false;
}

And I think you need to change your view model too

0
2/3/2015 11:15:04 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow