public static void Main() { PasswordGenerator password = new PasswordGenerator(12); for (int i = 0; i < 100; i++) { Console.WriteLine(password.Generate()); } }
private static void Execute(ExecutionContext executionContext) { var generator = new PasswordGenerator(executionContext.RuleSet); for (int i = 0; i < executionContext.Count; i++) { string result = GeneratePassword(generator, executionContext.Length); Console.WriteLine(result); } }
// Scroll on main trackBar private void trackBarLength_Scroll(object sender, EventArgs e) { passwordLength = trackBarLength.Value; labelLength.Text = "Length: " + passwordLength.ToString(); passwordText = PasswordGenerator.Generate(passwordLength, (passwordLength / 2), true, true, true, true); //passwordText = GeneratePassword(passwordLength); labelPassword.Text = passwordText; buttonCopyPassword.Enabled = true; Text = appName + " " + appVersion + " - Generated a Password (" + passwordLength + " characters)"; //await Task.Delay(5000); //Text = appName + " " + appVersion; }
private static string GeneratePassword(PasswordGenerator generator, int length) { string result; using (var secureGenerated = generator.Generate(length)) { IntPtr ptr = Marshal.SecureStringToBSTR(secureGenerated); result = Marshal.PtrToStringUni(ptr); } return(result); }
// Click on "Generate Password" button private async void buttonGeneratePassword_Click(object sender, EventArgs e) { passwordText = PasswordGenerator.Generate(passwordLength, (passwordLength / 2), true, true, true, true); // passwordText = GeneratePassword(passwordLength); labelPassword.Text = passwordText; buttonCopyPassword.Enabled = true; buttonGeneratePassword.Text = "Generated"; Text = appName + " " + appVersion + " - Generated a Password (" + passwordLength + " characters)"; await Task.Delay(5000); buttonGeneratePassword.Text = "&Generate"; //Text = appName + " " + appVersion; }
private static void ExecuteWithDistributionAnalysis(ExecutionContext executionContext) { var generator = new PasswordGenerator(executionContext.RuleSet); Dictionary <CharacterSet, int> distribution = executionContext.RuleSet.Requirements.ToDictionary(r => r.CharacterSet, r => 0); Dictionary <CharacterSet, Dictionary <char, int> > setDistribution = executionContext.RuleSet.Requirements.ToDictionary(r => r.CharacterSet, r => r.CharacterSet.Chars.ToDictionary(c => c, c => 0)); for (int i = 0; i < executionContext.Count; i++) { string result = GeneratePassword(generator, executionContext.Length); Console.WriteLine(result); foreach (var c in result.ToCharArray()) { var type = distribution.Keys.Single(ct => ct.Chars.Contains(c)); distribution[type]++; setDistribution[type][c]++; } } Console.WriteLine(); Console.WriteLine("PASSWORD REQUIREMENTS"); Console.WriteLine(string.Join("\r\n\r\n", executionContext.RuleSet.Requirements.Select(r => r.GetDefinition()))); Console.WriteLine(); double totalCharCount = distribution.Values.Sum(); foreach (var kvp in setDistribution) { Console.WriteLine($"== {kvp.Key.Name} [{Math.Round(distribution[kvp.Key]/totalCharCount*100, 2)}] =="); double typeTotal = kvp.Value.Values.Sum(); foreach (var cKvp in kvp.Value.OrderByDescending(x => x.Value)) { Console.WriteLine($"{cKvp.Key} - {cKvp.Value} [{Math.Round(cKvp.Value/typeTotal*100, 2)}]"); } Console.WriteLine(); } }