static void Main(string[] args) { const int entropy = 128; // Example 1: Generate password using default random number generator using var defaultPasswordGenerator = new DefaultPasswordGenerator(); var password = defaultPasswordGenerator.GenerateAlphanumericPassword(entropy); Console.WriteLine(password); // Example 2: Generate password from custom character pool var pool = PasswordGenerator.Alphanumerics.Union(new int[] { '*', '.', '/', '?', '-', '.', '_' }); password = defaultPasswordGenerator.GeneratePassword(entropy, pool); Console.WriteLine(password); // Example 3: Generate password using custom random number generator using (var randomNumberGenerator = new RNGCryptoServiceProvider()) { var passwordGenerator = new PasswordGenerator(randomNumberGenerator); password = passwordGenerator.GenerateAlphanumericPassword(entropy); } Console.WriteLine(password); }
public void Should_throw_exception_on_invalid_domain_name() { DefaultPasswordGenerator d = new DefaultPasswordGenerator(GetDefaultSettingsReader()); var user = GetUser(); user.MyShopifyDomain = null; Assert.Throws <Exception>(() => d.GetPassword(new PasswordGeneratorInfo(user))).Message.Contains("My shopify domain name is not valid"); }
public void Generate() { using (var gen = new DefaultPasswordGenerator(new CryptoRandomNumberGenerator())) { var val = gen.Generate(1, TextLength == 0 ? 6 : TextLength, true, true, true, false, null, 2, 2, 2, PasswordStrengthEnum.NotDefined); _text = val[0].Value; } _children.Clear(); _children.Add(CreateVisual()); InvalidateVisual(); }
public void Should_generate_valid_passwords() { var user = GetUser(); DefaultPasswordGenerator d = new DefaultPasswordGenerator(GetDefaultSettingsReader()); var pass = d.GetPassword(new PasswordGeneratorInfo(user)); var pass1 = d.GetPassword(new PasswordGeneratorInfo(user.MyShopifyDomain, user.Email)); Assert.NotNull(pass); Assert.NotNull(pass1); Assert.Equal(pass, pass1); //Assert.Equal(ValidPassword, pass); }
static void StartGeneration() { DisplaySelectedArguments(); Console.WriteLine("Generation started"); var st = new Stopwatch(); st.Start(); Password[] passwords = null; try { using (var gen = new DefaultPasswordGenerator(new CryptoRandomNumberGenerator())) { passwords = gen.Generate(count, length, forceNumber, forceLower, forceUpper, useSymbols, dictionary, minNumber, minLower, minUpper, (PasswordStrengthEnum)minStrength); } } catch (Exception exp) { Console.WriteLine("ERROR: {0}", exp.Message); return; } finally { st.Stop(); } if (string.IsNullOrEmpty(outputfile)) { foreach (var password in passwords) { Console.WriteLine(password); } } else { WritePasswordsToFile(outputfile, passwords); } Console.WriteLine("Generation finished. Elapsed time : {0}.", st.Elapsed); }