Skip to content

Commit

Permalink
Added guard clause to password criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMi-Ha committed Nov 7, 2023
1 parent ddbd233 commit dc32aa8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions PWManager.Domain/ValueObjects/PasswordGeneratorCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PasswordGeneratorCriteria : ValueObject {
public int MinLength { get; }
public int MaxLength { get; }

public PasswordGeneratorCriteria(bool includeLowerCase, bool includeUppercase, bool includeNumeric, bool includeSpecial, bool includeBrackets, bool includeSpaces, int minLength, int maxLength) {
public PasswordGeneratorCriteria(bool includeLowerCase, bool includeUpperCase, bool includeNumeric, bool includeSpecial, bool includeBrackets, bool includeSpaces, int minLength, int maxLength) {
if (MinLength <= 0) {
throw new ArgumentException("MinLength cannot be less than or equal to 0");
}
Expand All @@ -23,13 +23,17 @@ public PasswordGeneratorCriteria(bool includeLowerCase, bool includeUppercase, b
}

IncludeLowerCase = includeLowerCase;
IncludeUpperCase = includeUppercase;
IncludeUpperCase = includeUpperCase;
IncludeNumeric = includeNumeric;
IncludeSpecial = includeSpecial;
IncludeBrackets = includeBrackets;
IncludeSpaces = includeSpaces;
MinLength = minLength;
MaxLength = maxLength;

if (NoCharactersIncluded()) {
throw new ArgumentException("Password Generator must have some characters enabled!");
}
}

protected override IEnumerable<object> GetEqualityComponents() {
Expand All @@ -42,5 +46,9 @@ protected override IEnumerable<object> GetEqualityComponents() {
yield return MinLength;
yield return MaxLength;
}

private bool NoCharactersIncluded() {
return !IncludeLowerCase && !IncludeUpperCase && !IncludeNumeric && !IncludeSpecial && !IncludeBrackets;
}
}
}

0 comments on commit dc32aa8

Please sign in to comment.