Example #1
0
        private static Task Generate(CommandLineOptions options)
        {
            try
            {
                var transformer = TransformerFactory.CreateFromKeywords(options.Transformations);

                if (string.IsNullOrEmpty(options.WordsDirectory))
                {
                    string?dllPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    options.WordsDirectory = Path.Combine(dllPath ?? "", "content", Language.Get(options.Language));
                }

                var generator = PasswordGeneratorFactory.Create(
                    Path.Join(options.WordsDirectory, WordDirectoryConfig.AdjectiveDirectoryName),
                    Path.Join(options.WordsDirectory, WordDirectoryConfig.NounDirectoryName),
                    WordDirectoryConfig.AdjectiveFileNameRegex,
                    WordDirectoryConfig.NounFileNameRegex
                    );

                int numberOfGeneratedPasswords = options.PasswordCount;
                while (numberOfGeneratedPasswords-- > 0)
                {
                    var password            = generator.Generate(options.PasswordLength);
                    var transformedPassword = transformer.Transform(password);
                    Console.WriteLine(transformedPassword + " (Original: \"" + password + "\")");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error while generating password:\n\n{0}", ex);
            }

            return(Task.CompletedTask);
        }
Example #2
0
        private string GetOutput(RestPasswordParameters parameters)
        {
            var         passwords   = new List <Password>();
            Transformer transformer = TransformerFactory.CreateFromKeywords(parameters.Transformations);

            for (int i = 0; i < parameters.PasswordCount; i++)
            {
                Password password            = passwordGenerator.Generate(parameters.Language, parameters.PasswordLength);
                Password transformedPassword = transformer.Transform(password);
                passwords.Add(transformedPassword);
            }

            return(this.GenerateOutput(passwords, parameters.JsonOutput));
        }