Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Identity Provider SignInManager Keeps Returning Failure

I have an issue with the standard ASP Identity provider for MVC5. As soon as I log in the method:

await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

keeps returning Failure. So I started debugging, By using:

UserManager.FindByEmail(model.Email);

This returns a valid UserID for my user trying to log in. Then I used:

SignInManager.UserManager.CheckPassword(UserIDObtainedFromFind, model.Password);

And this returns true, which means that the password I provide is valid....

Sign In failure

Any ideas on how I can trace, of debug the SignInManager.PasswordSignInAsync method to see where it fails?

like image 446
Jacques Bronkhorst Avatar asked Oct 17 '14 17:10

Jacques Bronkhorst


3 Answers

SignInManager.PasswordSignIn works off of user name, you should double check that the user name is the same as the email you are passing in.

like image 60
Hao Kung Avatar answered Nov 11 '22 20:11

Hao Kung


If username != email:

ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
like image 31
Владимир Ш. Avatar answered Nov 11 '22 21:11

Владимир Ш.


In my case the same probe validating the email and password, the email is the same as my user.

    var userDO = _userManager.FindByEmailAsync(Input.Email).Result;
    var validatr = _userManager.CheckPasswordAsync(userDO, Input.Password);

email = userName

true result

Then I checked the database and found that the verification field of the user that did not work is false

enter image description here

Then the verification parameter must be validated in the startup. that is inside the Startup.cs

public void ConfigureServices(ServiceCollection services)
{
//......
            services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
                .AddRoles<IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>();
//......
}

enter image description here

The above property setting Gets or sets a flag indicating whether a confirmed IUserConfirmation account is required to sign in

options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;

Bye!

like image 7
Pablo Silva Avatar answered Nov 11 '22 19:11

Pablo Silva