ASP.NET Authentication 2 Separating Email and Username and Using Email to Login

By default, ASP.NET ID has UserName and Email fields as the email address that the user enters. I've already changed it so that my system takes a separate username and email address for the user.

My problem is that now I am unable to login due to the checks that Identity does against both UserName and Email.

I was wondering if there is a way to keep these two fields separate and unique, while being able to just check the email field to log in?

I noticed that I was public virtual Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout);

checking username, but changing that message to email does nothing and I still can't log in.

I also looked at these other questions:

ASP.Net username for email

Allow authentication by both email and username

for possible solutions and didn't find anything that actually allowed me to do what I want.

Is there anything else I could try in order to have separate usernames and emails, but can still login with the email field?


source to share

1 answer

So, it looks like you can only authenticate with the username, but there is no reason why you cannot find the username from the email address:

var user = await UserManager.FindByEmailAsync(model.Email);
if (user == null)

    return //some error or throw
var result = await 
                                      shouldLockout: false);




All Articles