locked
Problems signing in with userManager. RRS feed

  • Question

  • User-1204637165 posted

    I am using the default authentication to signup a user and it works well. But when I try to signin with that newly created account I get a failed notification that result.Succeeded is false.

    I am very very sure of the password that I am using to login. I have tried severally but I dont know what the problem is. SO I have to come here to ask you guys.

    I am using asp.net core 3.1. I would probably paste snippet of my code here. I need help cos this error is slowing me down from meeting up with requirements.

    My startup class  ConfigureService method.

     services.AddIdentity<ApplicationUser, IdentityRole>() //(options => options.SignIn.RequireConfirmedAccount = true)
                    .AddEntityFrameworkStores<DatabaseContext>()
                    .AddDefaultTokenProviders();
    
                services.Configure<IdentityOptions>(options =>
                {
                    //Password settings
                    options.Password.RequireDigit = true;
                    options.Password.RequiredLength = 8;
                    options.Password.RequireNonAlphanumeric = false;
                    options.Password.RequireUppercase = false ;
                    options.Password.RequireLowercase = false;
                });
    

    Configure method.

     app.UseHttpsRedirection(); //This is going to enable http request to be redirectexd over https
    
                app.UseRouting();
    
                //app.UseCertificateForwarding(); //This is here for custom certificate
    
                app.UseAuthorization();
    
                app.UseAuthentication(); //This would enable ClaimsPrincipal
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });

    Sign method in my Wep api controller

    if (ModelState.IsValid)
                {
                    try
                    {
                        var user = new ApplicationUser() { Email = model.Email };
    
                        var signedin = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);
    
                        var result = await _signInManager.PasswordSignInAsync(user, model.Password, model.RememberMe, lockoutOnFailure: false);
    
                        if (result.Succeeded)
                        {
                            _logger.LogInformation("User logged in.");
                            responsemodel.Response = "success";
                            responsemodel.Details = "Successful";
                        }
                        else
                        {
                            _logger.LogInformation("User login failed.");
                            responsemodel.Response = "failed";
                            responsemodel.Details = "Wrong username or password";
                        }
    
    ......................................

    Honestly I dont konw were the problem is coming from

    Sunday, March 29, 2020 5:57 PM

Answers

  • User-1204637165 posted

    So I added this line before checkPasswordSigninasync

    var result0 = await _userManager.FindByEmailAsync(model.Email);

    It returns email. But dont know what the problem is. The main problem is when I check is signedin.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 6:49 PM
  • User-1204637165 posted

    So I found the error. I check my code and I discovered that I was suppose to pass email instead of user object.

        var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);

    This fixed the entire problem that I was facing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 7:51 PM

All replies

  • User-474980206 posted

    You should use the debugger and check the model values are correct and why the login failed.

    Sunday, March 29, 2020 6:41 PM
  • User-1204637165 posted

    So I added this line before checkPasswordSigninasync

    var result0 = await _userManager.FindByEmailAsync(model.Email);

    It returns email. But dont know what the problem is. The main problem is when I check is signedin.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 6:49 PM
  • User-1204637165 posted

    So I found the error. I check my code and I discovered that I was suppose to pass email instead of user object.

        var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);

    This fixed the entire problem that I was facing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 29, 2020 7:51 PM