Possible wrong error message from ChangePasswordAsync
Hi
I believe the method ChangePasswordAsync in Microsoft.AspNetCore.Identity.UserManager can return wrong error message. If I type in a wrong currrentPassword, It will return the error message PasswordMismatch. It shoud return a IncorrectPassword message. Otherwise there will be no diffrence in 2 different new passwords and wrong current password.
Here is the method:
public virtual async Task<IdentityResult> ChangePasswordAsync(TUser user, string currentPassword, string newPassword)
{
ThrowIfDisposed();
var passwordStore = GetPasswordStore();
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
if (await VerifyPasswordAsync(passwordStore, user, currentPassword) != PasswordVerificationResult.Failed)
{
var result = await UpdatePasswordHash(passwordStore, user, newPassword);
if (!result.Succeeded)
{
return result;
}
return await UpdateUserAsync(user);
}
Logger.LogWarning(2, "Change password failed for user {userId}.", await GetUserIdAsync(user));
return IdentityResult.Failed(ErrorDescriber.PasswordMismatch());
}
This is deliberate. Say someone left themselves logged in and you got hold of their browser. We don't want to give any information away - so we don't tell you if you got the current password wrong, or if there's a mismatch.
We could revisit this in 2.1.
Upon discussion we feel this is giving too much information in an error message, and a failure is failure. Considering the check for new password 1 and new password 2 is outside of this error you could instead implement yourself.