/// <summary> /// Counts the total number of records in a local instance of Pwned Passwords. /// </summary> /// <param name="args">The command-line argments passed to the application.</param> private static void CardinalityMode(string[] args) { // Check database file path was passed. if (args.Length < 2) { Console.WriteLine("Pwned Passwords database file must be specified."); return; } // Check file exists. var filename = args[1]; if (!File.Exists(filename)) { Console.WriteLine($"Could not read Pwned Passwords database at '{filename}'."); return; } // Pass output back to user. var service = new LocalFilePwnedFrequencyExtractor(filename); Console.WriteLine($"Computing cardinality of database at '{filename}'..."); Console.WriteLine($"{service.GetCardinality()} individual passwords found."); }
/// <summary> /// Retrieves frequencies from a local instance of Pwned Passwords. /// </summary> /// <param name="args">The command-line arguments passed to the application.</param> private static void FrequencyMode(string[] args) { // Check database file path was passed. if (args.Length < 2) { Console.WriteLine("Pwned Passwords database file must be specified."); return; } // Check file exists. var filename = args[1]; if (!File.Exists(filename)) { Console.WriteLine($"Could not read Pwned Passwords database at '{filename}'."); return; } // Check query type was specified. if (args.Length < 3) { Console.WriteLine("Query type must be specified (-l or -t)."); return; } // Get ready to query file. var service = new LocalFilePwnedFrequencyExtractor(filename); IList <int> results = new List <int>(); // Switch on query type. switch (args[2]) { case "-l": // Check limit was specified. if (args.Length < 4) { Console.WriteLine("Limit must be specified."); return; } // Check limit parses as an integer. if (!int.TryParse(args[3], out var limit)) { Console.WriteLine("Invalid limit provided."); return; } results = service.GetAbove(limit); // Get frequencies above `limit`. break; case "-t": // Check count was specified. if (args.Length < 4) { Console.WriteLine("Count must be specified."); return; } // Check count parses as an integer. if (!int.TryParse(args[3], out var count)) { Console.WriteLine("Invalid count provided."); return; } results = service.GetTop(count); // Get `count` top frequencies. break; default: // Invalid query type specified. Console.WriteLine("Invalid query type specified (Use -h for help)."); break; } // Output goes straight to console. foreach (var entry in results) { Console.WriteLine(entry); } }