RequiresNonLetterOrDigit => RequiresNonAlphanumeric
This commit is contained in:
parent
58b2cf6c7d
commit
84804fec20
|
|
@ -233,12 +233,12 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="length">The length that is not long enough.</param>
|
||||
/// <returns>An <see cref="IdentityError"/> indicating a password entered does not contain a non-alphanumeric character.</returns>
|
||||
public virtual IdentityError PasswordRequiresNonLetterAndDigit()
|
||||
public virtual IdentityError PasswordRequiresNonAlphanumeric()
|
||||
{
|
||||
return new IdentityError
|
||||
{
|
||||
Code = nameof(PasswordRequiresNonLetterAndDigit),
|
||||
Description = Resources.PasswordRequiresNonLetterAndDigit
|
||||
Code = nameof(PasswordRequiresNonAlphanumeric),
|
||||
Description = Resources.PasswordRequiresNonAlphanumeric
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ namespace Microsoft.AspNet.Identity
|
|||
public int RequiredLength { get; set; } = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating if passwords must contain a digit or other non-alphabetical character.
|
||||
/// Gets or sets a flag indicating if passwords must contain a non-alphanumeric character.
|
||||
/// </summary>
|
||||
/// <value>True if passwords must contain a digit or other non-alphabetical character, otherwise false.</value>
|
||||
/// <value>True if passwords must contain a non-alphanumeric character, otherwise false.</value>
|
||||
/// <remarks>
|
||||
/// This defaults to true.
|
||||
/// </remarks>
|
||||
public bool RequireNonLetterOrDigit { get; set; } = true;
|
||||
public bool RequireNonAlphanumeric { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating if passwords must contain a lower case ASCII character.
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ namespace Microsoft.AspNet.Identity
|
|||
{
|
||||
errors.Add(Describer.PasswordTooShort(options.RequiredLength));
|
||||
}
|
||||
if (options.RequireNonLetterOrDigit && password.All(IsLetterOrDigit))
|
||||
if (options.RequireNonAlphanumeric && password.All(IsLetterOrDigit))
|
||||
{
|
||||
errors.Add(Describer.PasswordRequiresNonLetterAndDigit());
|
||||
errors.Add(Describer.PasswordRequiresNonAlphanumeric());
|
||||
}
|
||||
if (options.RequireDigit && !password.Any(IsDigit))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// An unknown failure has occured.
|
||||
/// An unknown failure has occurred.
|
||||
/// </summary>
|
||||
internal static string DefaultError
|
||||
{
|
||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// An unknown failure has occured.
|
||||
/// An unknown failure has occurred.
|
||||
/// </summary>
|
||||
internal static string FormatDefaultError()
|
||||
{
|
||||
|
|
@ -299,19 +299,19 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Passwords must have at least one non letter and non digit character.
|
||||
/// Passwords must have at least one non alphanumeric character.
|
||||
/// </summary>
|
||||
internal static string PasswordRequiresNonLetterAndDigit
|
||||
internal static string PasswordRequiresNonAlphanumeric
|
||||
{
|
||||
get { return GetString("PasswordRequiresNonLetterAndDigit"); }
|
||||
get { return GetString("PasswordRequiresNonAlphanumeric"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Passwords must have at least one non letter and non digit character.
|
||||
/// Passwords must have at least one non alphanumeric character.
|
||||
/// </summary>
|
||||
internal static string FormatPasswordRequiresNonLetterAndDigit()
|
||||
internal static string FormatPasswordRequiresNonAlphanumeric()
|
||||
{
|
||||
return GetString("PasswordRequiresNonLetterAndDigit");
|
||||
return GetString("PasswordRequiresNonAlphanumeric");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -189,9 +189,9 @@
|
|||
<value>Passwords must have at least one lowercase ('a'-'z').</value>
|
||||
<comment>Error when passwords do not have a lowercase letter</comment>
|
||||
</data>
|
||||
<data name="PasswordRequiresNonLetterAndDigit" xml:space="preserve">
|
||||
<value>Passwords must have at least one non letter and non digit character.</value>
|
||||
<comment>Error when password does not have enough letter or digit characters</comment>
|
||||
<data name="PasswordRequiresNonAlphanumeric" xml:space="preserve">
|
||||
<value>Passwords must have at least one non alphanumeric character.</value>
|
||||
<comment>Error when password does not have enough non alphanumeric characters</comment>
|
||||
</data>
|
||||
<data name="PasswordRequiresUpper" xml:space="preserve">
|
||||
<value>Passwords must have at least one uppercase ('A'-'Z').</value>
|
||||
|
|
@ -281,4 +281,4 @@
|
|||
<value>User is not in role '{0}'.</value>
|
||||
<comment>Error when a user is not in the role</comment>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Identity.InMemory
|
|||
var server = CreateServer(services => services.Configure<IdentityOptions>(options =>
|
||||
{
|
||||
options.Password.RequireUppercase = false;
|
||||
options.Password.RequireNonLetterOrDigit = false;
|
||||
options.Password.RequireNonAlphanumeric = false;
|
||||
options.Password.RequireDigit = false;
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
|
||||
Assert.True(options.Password.RequireDigit);
|
||||
Assert.True(options.Password.RequireLowercase);
|
||||
Assert.True(options.Password.RequireNonLetterOrDigit);
|
||||
Assert.True(options.Password.RequireNonAlphanumeric);
|
||||
Assert.True(options.Password.RequireUppercase);
|
||||
Assert.Equal(6, options.Password.RequiredLength);
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
{"identity:claimsidentity:securitystampclaimtype", securityStampClaimType},
|
||||
{"identity:user:requireUniqueEmail", "true"},
|
||||
{"identity:password:RequiredLength", "10"},
|
||||
{"identity:password:RequireNonLetterOrDigit", "false"},
|
||||
{"identity:password:RequireNonAlphanumeric", "false"},
|
||||
{"identity:password:RequireUpperCase", "false"},
|
||||
{"identity:password:RequireDigit", "false"},
|
||||
{"identity:password:RequireLowerCase", "false"},
|
||||
|
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
Assert.Equal("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@", options.User.AllowedUserNameCharacters);
|
||||
Assert.False(options.Password.RequireDigit);
|
||||
Assert.False(options.Password.RequireLowercase);
|
||||
Assert.False(options.Password.RequireNonLetterOrDigit);
|
||||
Assert.False(options.Password.RequireNonAlphanumeric);
|
||||
Assert.False(options.Password.RequireUppercase);
|
||||
Assert.Equal(10, options.Password.RequiredLength);
|
||||
Assert.False(options.Lockout.AllowedForNewUsers);
|
||||
|
|
@ -129,7 +129,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var myOptions = optionsGetter.Value;
|
||||
Assert.True(myOptions.Password.RequireLowercase);
|
||||
Assert.True(myOptions.Password.RequireDigit);
|
||||
Assert.True(myOptions.Password.RequireNonLetterOrDigit);
|
||||
Assert.True(myOptions.Password.RequireNonAlphanumeric);
|
||||
Assert.True(myOptions.Password.RequireUppercase);
|
||||
Assert.Equal(-1, myOptions.Password.RequiredLength);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var manager = MockHelpers.TestUserManager<TestUser>();
|
||||
var valid = new PasswordValidator<TestUser>();
|
||||
manager.Options.Password.RequireUppercase = false;
|
||||
manager.Options.Password.RequireNonLetterOrDigit = false;
|
||||
manager.Options.Password.RequireNonAlphanumeric = false;
|
||||
manager.Options.Password.RequireLowercase = false;
|
||||
manager.Options.Password.RequireDigit = false;
|
||||
IdentityResultAssert.IsFailure(await valid.ValidateAsync(manager, null, input), error);
|
||||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var manager = MockHelpers.TestUserManager<TestUser>();
|
||||
var valid = new PasswordValidator<TestUser>();
|
||||
manager.Options.Password.RequireUppercase = false;
|
||||
manager.Options.Password.RequireNonLetterOrDigit = false;
|
||||
manager.Options.Password.RequireNonAlphanumeric = false;
|
||||
manager.Options.Password.RequireLowercase = false;
|
||||
manager.Options.Password.RequireDigit = false;
|
||||
IdentityResultAssert.IsSuccess(await valid.ValidateAsync(manager, null, input));
|
||||
|
|
@ -73,12 +73,12 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var manager = MockHelpers.TestUserManager<TestUser>();
|
||||
var valid = new PasswordValidator<TestUser>();
|
||||
manager.Options.Password.RequireUppercase = false;
|
||||
manager.Options.Password.RequireNonLetterOrDigit = true;
|
||||
manager.Options.Password.RequireNonAlphanumeric = true;
|
||||
manager.Options.Password.RequireLowercase = false;
|
||||
manager.Options.Password.RequireDigit = false;
|
||||
manager.Options.Password.RequiredLength = 0;
|
||||
IdentityResultAssert.IsFailure(await valid.ValidateAsync(manager, null, input),
|
||||
"Passwords must have at least one non letter and non digit character.");
|
||||
"Passwords must have at least one non alphanumeric character.");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var manager = MockHelpers.TestUserManager<TestUser>();
|
||||
var valid = new PasswordValidator<TestUser>();
|
||||
manager.Options.Password.RequireUppercase = false;
|
||||
manager.Options.Password.RequireNonLetterOrDigit = true;
|
||||
manager.Options.Password.RequireNonAlphanumeric = true;
|
||||
manager.Options.Password.RequireLowercase = false;
|
||||
manager.Options.Password.RequireDigit = false;
|
||||
manager.Options.Password.RequiredLength = 0;
|
||||
|
|
@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[InlineData("aB1@df", Errors.None)]
|
||||
public async Task UberMixedRequiredTests(string input, Errors errorMask)
|
||||
{
|
||||
const string alphaError = "Passwords must have at least one non letter and non digit character.";
|
||||
const string alphaError = "Passwords must have at least one non alphanumeric character.";
|
||||
const string upperError = "Passwords must have at least one uppercase ('A'-'Z').";
|
||||
const string lowerError = "Passwords must have at least one lowercase ('a'-'z').";
|
||||
const string digitError = "Passwords must have at least one digit ('0'-'9').";
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
{
|
||||
options.Password.RequireDigit = false;
|
||||
options.Password.RequireLowercase = false;
|
||||
options.Password.RequireNonLetterOrDigit = false;
|
||||
options.Password.RequireNonAlphanumeric = false;
|
||||
options.Password.RequireUppercase = false;
|
||||
options.User.AllowedUserNameCharacters = null;
|
||||
}).AddDefaultTokenProviders();
|
||||
|
|
|
|||
Loading…
Reference in New Issue