Skip to content

Always call virtual UpdatePasswordHash #60252 #60592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/Identity/Extensions.Core/src/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,9 @@
public virtual async Task<IdentityResult> CreateAsync(TUser user, string password)
{
ThrowIfDisposed();
var passwordStore = GetPasswordStore();
ArgumentNullThrowHelper.ThrowIfNull(user);
ArgumentNullThrowHelper.ThrowIfNull(password);
var result = await UpdatePasswordHash(passwordStore, user, password).ConfigureAwait(false);
var result = await UpdatePasswordHash(user, password, validatePassword: true).ConfigureAwait(false);
if (!result.Succeeded)
{
return result;
Expand Down Expand Up @@ -684,7 +683,7 @@
var result = await VerifyPasswordAsync(passwordStore, user, password).ConfigureAwait(false);
if (result == PasswordVerificationResult.SuccessRehashNeeded)
{
await UpdatePasswordHash(passwordStore, user, password, validatePassword: false).ConfigureAwait(false);
await UpdatePasswordHash(user, password, validatePassword: false).ConfigureAwait(false);
await UpdateUserAsync(user).ConfigureAwait(false);
}

Expand Down Expand Up @@ -735,7 +734,7 @@
Logger.LogDebug(LoggerEventIds.UserAlreadyHasPassword, "User already has a password.");
return IdentityResult.Failed(ErrorDescriber.UserAlreadyHasPassword());
}
var result = await UpdatePasswordHash(passwordStore, user, password).ConfigureAwait(false);
var result = await UpdatePasswordHash(user, password, validatePassword: true).ConfigureAwait(false);
if (!result.Succeeded)
{
return result;
Expand All @@ -762,7 +761,7 @@

if (await VerifyPasswordAsync(passwordStore, user, currentPassword).ConfigureAwait(false) != PasswordVerificationResult.Failed)
{
var result = await UpdatePasswordHash(passwordStore, user, newPassword).ConfigureAwait(false);
var result = await UpdatePasswordHash(user, newPassword, validatePassword: true).ConfigureAwait(false);
if (!result.Succeeded)
{
return result;
Expand All @@ -784,10 +783,9 @@
public virtual async Task<IdentityResult> RemovePasswordAsync(TUser user)
{
ThrowIfDisposed();
var passwordStore = GetPasswordStore();
ArgumentNullThrowHelper.ThrowIfNull(user);

await UpdatePasswordHash(passwordStore, user, null, validatePassword: false).ConfigureAwait(false);
await UpdatePasswordHash(user, null, validatePassword: false).ConfigureAwait(false);

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.

Check failure on line 788 in src/Identity/Extensions.Core/src/UserManager.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Identity/Extensions.Core/src/UserManager.cs#L788

src/Identity/Extensions.Core/src/UserManager.cs(788,40): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type.
return await UpdateUserAsync(user).ConfigureAwait(false);
}

Expand Down Expand Up @@ -2211,12 +2209,9 @@
/// <param name="newPassword">The new password.</param>
/// <param name="validatePassword">Whether to validate the password.</param>
/// <returns>Whether the password has was successfully updated.</returns>
protected virtual Task<IdentityResult> UpdatePasswordHash(TUser user, string newPassword, bool validatePassword)
=> UpdatePasswordHash(GetPasswordStore(), user, newPassword, validatePassword);

private async Task<IdentityResult> UpdatePasswordHash(IUserPasswordStore<TUser> passwordStore,
TUser user, string? newPassword, bool validatePassword = true)
protected virtual async Task<IdentityResult> UpdatePasswordHash(TUser user, string newPassword, bool validatePassword)
{
var passwordStore = GetPasswordStore();
if (validatePassword)
{
var validate = await ValidatePasswordAsync(user, newPassword).ConfigureAwait(false);
Expand Down
Loading