Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ASP.NET Core MVC 3.1 project wont let me sign in with a register user using Identity

I have scaffolded the Login View to create my own, but the thing is that whenever I tried to Login to the application an invalid login attempt error appears as if it is not finding the user. Cant seem to find a solution to this. Can someone help me please!!!

This is the code I'm using and it was autogenerated:

 var result = await _signInManager.PasswordSignInAsync(user.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false);                
if (result.Succeeded)
{
   _logger.LogInformation("User logged in.");
   return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
   return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut)
{
  _logger.LogWarning("User account locked out.");
  return RedirectToPage("./Lockout");
}
else
{
   ModelState.AddModelError(string.Empty, "Invalid login attempt.");
   return Page();
}
like image 451
wrabarias Avatar asked Dec 03 '22 09:12

wrabarias


1 Answers

By using default scaffold Identity,I could reproduce your issue if you do not confirm your email.Here are two ways to resolve your issue.

1.You could click the following link to confirm the email like below:

enter image description here 2.Or you could set RequireConfirmedAccount=false like below:

services.AddDefaultIdentity<IdentityUser>(
             options => options.SignIn.RequireConfirmedAccount = false)
            .AddEntityFrameworkStores<ApplicationDbContext>();
like image 177
Rena Avatar answered Dec 09 '22 15:12

Rena