Identity icon indicating copy to clipboard operation
Identity copied to clipboard

Possible wrong error message from ChangePasswordAsync

Open AxelDalenAndersenP opened this issue 9 years ago • 2 comments

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());
        }

AxelDalenAndersenP avatar Jul 04 '17 07:07 AxelDalenAndersenP

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.

blowdart avatar Jul 05 '17 19:07 blowdart

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.

blowdart avatar Oct 12 '17 19:10 blowdart