Skip to content

Commit 10d935a

Browse files
author
Adit Sheth
committed
Fixed to not throw an exception when password is null.
1 parent fdd6d10 commit 10d935a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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]
32-
[InlineData("")]
33-
[InlineData("abc")]
34-
[InlineData("abcde")]
35-
public async Task FailsIfTooShortTests(string input)
31+
[InlineData(null)]
32+
[InlineData("")]
33+
[InlineData("abc")]
34+
[InlineData("abcde")]
35+
public async Task FailsIfPasswordIsNullOrTooShort(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)