当前位置:网站首页>ASP. NET CORE3. 1. Solution to login failure after identity registers users

ASP. NET CORE3. 1. Solution to login failure after identity registers users

2022-04-23 17:05:00 begeneral

Let's look at the failure first :

This is a user I registered with my own email , Registration was successful , There is also this record in the database

But you see EmailConfirmed The value of the field is 0, It means that this mailbox has not been verified . Generally speaking , If it is registered by email , The system will send a verification email to your email . But I didn't verify this email here .

In fact, the problem lies in this field , The solution is to let Identity Don't verify this email when logging in , The code is as follows :

services.Configure<IdentityOptions>(options =>
            {
                // Password settings. Password configuration 
                options.Password.RequireDigit = true;
                options.Password.RequireLowercase = true;
                options.Password.RequireNonAlphanumeric = true;
                options.Password.RequireUppercase = true;
                options.Password.RequiredLength = 6;
                options.Password.RequiredUniqueChars = 1;            
                // Set whether an authenticated mailbox is required for login 
                options.SignIn.RequireConfirmedAccount = false;

                // Lockout settings. Lock settings 
                options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers = true;
            });

The property set is :options.SignIn.RequireConfirmedAccount. Log in again after setting , It is found that the login succeeded .

We can also from ASP.NET CORE Source code to find the answer ( Need to download first ASP.NET CORE3.1 Source code ). The function we use to log in is SignInManager Class PasswordSignInAsync function ,

Source location :aspnetcore\src\Identity, open Identity.sln Solution , find src\Microsoft.AspNetCore.Identiy\SignInManager.cs file . find PasswordSignInAsync After the function , Go step by step

After the definition of the subfunction , find CanSignInAsync function , The screenshot of the function code is as follows :

The setting just now is judged here , The log output here can also be in ASP.NET CORE The console sees :

 

 

版权声明
本文为[begeneral]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554081936.html