public static bool validPasswordPart1(ILogger log, PasswordSpec passwordSpec) { var occurrences = 0; for (var i = 0; i < passwordSpec.Password.Length; i++) { if (passwordSpec.Password[i] == passwordSpec.Letter) { occurrences++; } } return(occurrences >= passwordSpec.FirstParameter && occurrences <= passwordSpec.SecondParameter); }
public static bool validPasswordPart2(ILogger logger, PasswordSpec passwordSpec) { return(passwordSpec.Password[passwordSpec.FirstParameter - 1] == passwordSpec.Letter ^ passwordSpec.Password[passwordSpec.SecondParameter - 1] == passwordSpec.Letter); }