Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problems signing in with userManager.

$
0
0

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 thatresult.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


Viewing all articles
Browse latest Browse all 9386

Trending Articles