Пример #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);
        }
Пример #2
0
        public string Get([FromQuery] PasswordParameters parameters)
        {
            this.logger.LogInformation($"Incoming request with parameters: {parameters}");

            string            languageSymbol = Language.Get(parameters.Language);
            PasswordGenerator generator      = PasswordGeneratorFactory.Create(
                Path.Combine(this.wordsDirectory, languageSymbol, "adjectives"),
                Path.Combine(this.wordsDirectory, languageSymbol, "nouns"),
                "adjectives_(\\d+).txt",
                "nouns_(\\d+).txt");

            return(generator.Generate(parameters.PasswordLength).ToString());
        }