'Why result.Succeeded return failed in ASP Identity

When trying to add the ability to add a name during registration, an error occurred when logging into the account. When I register, the login is successful, but as soon as I log out and try to log in again, the login error

Changes made to the log file

            var user = CreateUser();
            await _userStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None);
            await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
            var result = await _userManager.CreateAsync(user, Input.Password);

Here in UserNameAsync the standard value of the email, I will change it to the username

Part when where error

            if (ModelState.IsValid)
        {
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, set lockoutOnFailure: true
            var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
            if (result.Succeeded) //Return failed
            {
                _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();
            }
        }


Solution 1:[1]

You could check the EmailConfirmed Colum if it has a value in your database, If you registed with your e-mail,an e-mail will be sent to you to comfirm.and your error may caused by it.

You could also try to set as follow in your startup class to avoid the error

services.Configure<IdentityOptions>(options =>
            {
                ....
                options.SignIn.RequireConfirmedAccount = false;
                ....
             });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1