Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm creating a login and registration with Identity. Got a problem that when I register new account it logs in fine with SignInAsync, but when I try to log in from log in page with PasswordSignInAsync it doesn't succeed.

Here's my controller:

[HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Register(RegistrationViewModel model)
        if (ModelState.IsValid)
            var user = new User
                UserName = model.Username,
                Email = model.Email
            if (_userManager != null)
                var result = await _userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                    await _signInManager.SignInAsync(user, isPersistent: false);
                    return RedirectToAction("index", "home");
                foreach (var error in result.Errors)
                    ModelState.AddModelError("", error.Description);
        return View(model);
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Login(LoginViewModel model)
        if (ModelState.IsValid)
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
            if (result.Succeeded)
                return RedirectToAction("index", "home");
            ModelState.AddModelError(string.Empty, "Nepavyko prisijungti");
        return View(model);

Maybe someone knows what's the problem?

Well, I think SignInAsync issues an authentication cookie but delegates authentication process to another component (that you don't check in your code). so you might want to check if the credentials passed to PasswordSignInAsync are ok.

I mean, SignInAsync signs a user because it has been authenticated by other means. PasswordSignInAsync attempts to sign the requested user by using the Identity framework, matching the user with the provided password.

So the problem could be that the password is not correct, or is not properly issued to the server, or even the user does not exist...

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.