Skip to content

Commit

Permalink
Fix PasswordStrengthValidator not correctly validating MembershipSett…
Browse files Browse the repository at this point in the history
…ings.RequireDigit rule (#7306)

* Fix PasswordStrengthValidator not correctly validating MembershipSettings.RequireDigit rule

* Fix wrong message
  • Loading branch information
furkanevran authored Dec 30, 2024
1 parent 8e4d90f commit e250695
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class PasswordStrengthValidator(IOptions<MembershipSettings> membershipSe

public virtual void Validate(string password)
{
password ??= "";
password ??= string.Empty;

var rules = membershipSettings.Value;

if (password.Length < (rules.MinPasswordLength))
if (password.Length < rules.MinPasswordLength)
throw new ValidationError(nameof(MembershipSettings.MinPasswordLength), "Password",
string.Format(CultureInfo.CurrentCulture, PasswordStrengthValidationTexts.MinRequiredPasswordLength.ToString(localizer),
membershipSettings.Value.MinPasswordLength));
Expand Down Expand Up @@ -47,9 +47,9 @@ public virtual void Validate(string password)

if (rules.RequireLowercase && lowerCount == 0)
throw new ValidationError(nameof(rules.RequireLowercase), "Password",
PasswordStrengthValidationTexts.PasswordStrengthRequireUppercase.ToString(localizer));
PasswordStrengthValidationTexts.PasswordStrengthRequireLowercase.ToString(localizer));

if (rules.RequireDigit && lowerCount == 0)
if (rules.RequireDigit && numericCount == 0)
throw new ValidationError(nameof(rules.RequireDigit), "Password",
PasswordStrengthValidationTexts.PasswordStrengthRequireDigit.ToString(localizer));

Expand Down

0 comments on commit e250695

Please sign in to comment.