Skip to content

Commit 51b0c34

Browse files
authored
Fixed to not throw an exception when password is null. (#58168)
1 parent 403a72d commit 51b0c34

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Identity/Extensions.Core/src/PasswordValidator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public PasswordValidator(IdentityErrorDescriber? errors = null)
3939
/// <returns>The task object representing the asynchronous operation.</returns>
4040
public virtual Task<IdentityResult> ValidateAsync(UserManager<TUser> manager, TUser user, string? password)
4141
{
42-
ArgumentNullThrowHelper.ThrowIfNull(password);
4342
ArgumentNullThrowHelper.ThrowIfNull(manager);
4443
List<IdentityError>? errors = null;
4544
var options = manager.Options.Password;
45+
password ??= "";
4646
if (string.IsNullOrWhiteSpace(password) || password.Length < options.RequiredLength)
4747
{
4848
errors ??= new List<IdentityError>();

src/Identity/test/Identity.Test/PasswordValidatorTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public async Task ValidateThrowsWithNullTest()
2424

2525
// Act
2626
// Assert
27-
await Assert.ThrowsAsync<ArgumentNullException>("password", () => validator.ValidateAsync(null, null, null));
2827
await Assert.ThrowsAsync<ArgumentNullException>("manager", () => validator.ValidateAsync(null, null, "foo"));
2928
}
3029

3130
[Theory]
31+
[InlineData(null)]
3232
[InlineData("")]
3333
[InlineData("abc")]
3434
[InlineData("abcde")]
35-
public async Task FailsIfTooShortTests(string input)
35+
public async Task FailsIfPasswordIsNullOrTooShortTests(string input)
3636
{
3737
const string error = "Passwords must be at least 6 characters.";
3838
var manager = MockHelpers.TestUserManager<PocoUser>();

0 commit comments

Comments
 (0)