I'm starting my application, logging in and change my password (I'm using the default net .core identity):
IdentityResult identityResult =
await _userManager.ChangePasswordAsync(
applicationUser,
model.CurrentPassword,
model.NewPassword);
this works and in the database the new hashed password is stored.
Then, I'm logging out and try to login with the new password. But
if (await _userManager.CheckPasswordAsync(user, password))
return false. (Logging in with the old password still works, and I'm not caching anything)
When I'm restarting my application and trying to login with the new password, it works. I guess it's somewhere a problem with that PasswordStore (is there a caching?)? Any other suggestions what I may have forgotten or why this doesn't work?
edit:
the complete change password method:
[HttpPut]
[Route("api/user/changepassword/{ident}")]
public async Task<bool> ChangePassword(int ident, [FromBody]ChangePasswordModel model)
{
if (!ModelState.IsValid)
return false;
ApplicationUser applicationUser;
if ((applicationUser = await _userManager.FindByIdAsync(ident.ToString())) == null)
return false;
IdentityResult identityResult = await _userManager.ChangePasswordAsync(applicationUser, model.CurrentPassword, model.NewPassword);
return identityResult.Succeeded;
}
part from my startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
uservariable have the updated (new hash in the database) password?CheckPasswordAsyncit's part of the .net core identity.uservariable, when you use_userManager.CheckPasswordAsync(user, from where does thatusercome from?ApplicationUser user = await _userManager.FindByNameAsync(username);- so in the same context I get him new. But the user contains the old password hash. I saw, here is a user-store too in the usermanager