예제 #1
0
        private static void Main(string[] args)
        {
            var parsedArguments = new PasswordGeneratorArguments();

            if (!Parser.ParseArguments(args, parsedArguments))
            {
                System.Console.WriteLine(Parser.ArgumentsUsage(typeof(PasswordGeneratorArguments), 80));
            }
            else
            {
                Generate(parsedArguments);
            }
        }
예제 #2
0
        private static void Generate(PasswordGeneratorArguments parsedArguments)
        {
            IPasswordPolicy <string, int> passwordPolicy = PasswordPolicyFactory.Create(parsedArguments.PasswordPolicy);

            if (parsedArguments.PasswordPolicy == PasswordPolicyType.User)
            {
                ILengthStrategy lengthStrategy = parsedArguments.LengthPolicy == LengthStrategyType.Fixed
                                                     ? new FixedLengthStrategy(parsedArguments.PasswordLength) as
                                                 ILengthStrategy
                                                     : new VariableLengthStrategy(parsedArguments.MinPasswordLength,
                                                                                  parsedArguments.MaxPasswordLength);
                passwordPolicy
                .WithLengthStategy(lengthStrategy)
                .UseCatalog(StringCatalogFactory.Create(parsedArguments.Catalog))
                .UseRandom(RandomGeneratorFactory.Create(parsedArguments.RandomGeneration));
            }

            IPasswordGenerator <string> generator = new StringPasswordGenerator(passwordPolicy);

            for (int i = 0; i < parsedArguments.Count; i++)
            {
                System.Console.WriteLine(generator.Generate());
            }
        }