public static bool GetIsValidPassword(PasswordWrapper passwordWrapper) { if (passwordWrapper == null) { throw new ArgumentNullException(nameof(passwordWrapper)); } return(GetIsValidPassword(passwordWrapper.Password, passwordWrapper.Policy)); }
// Equals, GetHashCode, and ToString() adapted from Microsoft example here: // https://docs.microsoft.com/en-us/dotnet/api/system.object.equals?view=netcore-3.1 public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return(false); } else { PasswordWrapper p = (PasswordWrapper)obj; return((string.Equals(Password, p.Password)) && (Policy.Equals(p.Policy))); } }
public static PasswordWrapper ParsePassword(string passwordLine) { if (passwordLine == null) { throw new ArgumentNullException(nameof(passwordLine)); } string pattern = @"(\d+)\s?-\s?(\d+)\s(\w+):\s(\w+)"; var match = Regex.Match(passwordLine, pattern); if (match.Success) { var minOccurrences = int.Parse(match.Groups[1].Value); var maxOccurrences = int.Parse(match.Groups[2].Value); var requiredPhrase = match.Groups[3].Value; var password = match.Groups[4].Value; var policy = new PasswordPolicy(minOccurrences, maxOccurrences, requiredPhrase); var passwordWrapper = new PasswordWrapper(password, policy); return(passwordWrapper); } return(null); }