ASP.NET Identity - Find user by email and password

1

I am using Asp.Net Identity for the first time, along with the Entity Framework, and to create a user, I make the following code:

var identityUser = new IdentityUser
{
   UserName = viewModel.Nome.Replace(" ", "."),
   Email = viewModel.Email
};

IdentityResult resultado = userManager.Create(identityUser, viewModel.Senha);

So the user is free to enter his name in the first field viewModel.Nome and his email in the second viewModel.Email . To return this user at login time, I use the following code:

var usuario = userManager.Find(viewModel.Nome, viewModel.Senha);

My question is: Is it possible to fetch the user by E-mail, not by Name? that is, at the time of Find change viewModel.Nome by viewModel.Email ?

    
asked by anonymous 13.02.2018 / 15:26

1 answer

0

Problem solved. To do this, I retrieved the user by email, and soon after I logged in using his name, as follows:

var retorno = userManager.FindByEmail(viewModel.Login);
var usuario = userManager.Find(retorno.UserName, viewModel.Senha);
    
14.02.2018 / 15:04