title: Why sign in following Change Password in ASP.Net Core 2 MVC
body: <p>The default project template in Visual Studio 2017 contains a function in the ManageController for the logged in User to change their password.</p>
  
  <p>Following a successfull password change the user is then automatically signed in again</p>
  
  <pre><code>await _signInManager.SignInAsync(user, isPersistent: false);
  </code></pre>
  
  <p>What is the purpose of this sign in?</p>
  
  <p>The full action method is below:</p>
  
  <pre><code>[HttpPost]
      [ValidateAntiForgeryToken]
      public async Task&lt;IActionResult&gt; ChangePassword(ChangePasswordViewModel model)
      {
          if (!ModelState.IsValid)
          {
              return View(model);
          }
  
          var user = await _userManager.GetUserAsync(User);
          if (user == null)
          {
              throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
          }
  
          var changePasswordResult = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);
          if (!changePasswordResult.Succeeded)
          {
              AddErrors(changePasswordResult);
              return View(model);
          }
  
          await _signInManager.SignInAsync(user, isPersistent: false);
          _logger.LogInformation("User changed their password successfully.");
          StatusMessage = "Your password has been changed.";
  
          return RedirectToAction(nameof(ChangePassword));
      }
  </code></pre>