From a022576358a771f2b583cce75054e67a1b77407e Mon Sep 17 00:00:00 2001 From: MAC Date: Thu, 11 Jul 2019 11:34:07 +0200 Subject: [PATCH] Added optional capitalize feature --- ExampleApp/ExampleApp.cs | 2 +- README.md | 3 ++- XKCDPasswordGen/XKCDPasswordGen.cs | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ExampleApp/ExampleApp.cs b/ExampleApp/ExampleApp.cs index f723fd3..fbe1e39 100644 --- a/ExampleApp/ExampleApp.cs +++ b/ExampleApp/ExampleApp.cs @@ -10,7 +10,7 @@ static void Main(string[] args) var fourWordPassword = XkcdPasswordGen.Generate(4); Console.WriteLine("4 random words: " + fourWordPassword); - var dashPassword = XkcdPasswordGen.Generate(4, "-"); + var dashPassword = XkcdPasswordGen.Generate(4, "-",false,true); Console.WriteLine("4 random words separated by a dash: " + dashPassword); Console.ReadLine(); diff --git a/README.md b/README.md index e440225..051d490 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,11 @@ public class Program(){ ## API -### XkcdPasswordGen.Generate(int numWords, string separator = " ", bool crypto = true) +### XkcdPasswordGen.Generate(int numWords, string separator = " ", bool crypto = true, bool capital = false) | Option | Description | |-----------|------------------------------------------| | numWords | Number of words to be included in the generated password. | | separator | String to go inbetween each word in the generated password. | | crypto | Use cryptographicaly secure random number generator (Slower than standard random number generator). | +| capital | Capitalize first letter of password string to satisfy active directory password complexity requirements. | diff --git a/XKCDPasswordGen/XKCDPasswordGen.cs b/XKCDPasswordGen/XKCDPasswordGen.cs index 8802320..8b21981 100644 --- a/XKCDPasswordGen/XKCDPasswordGen.cs +++ b/XKCDPasswordGen/XKCDPasswordGen.cs @@ -29,8 +29,9 @@ static XkcdPasswordGen() /// Number of words to be included in the password /// String to go inbetween each word (defaults to a space) /// Use cryptographicaly secure random number generator (Slower than standard random number generator) + /// Capitalize first letter of password string to satisfy active directory password complexity requirements /// An XKCD style password - public static string Generate(int numWords, string separator = " ", bool crypto = true) + public static string Generate(int numWords, string separator = " ", bool crypto = true, bool capital = false) { Validator.RequireValidNumber(numWords); @@ -40,6 +41,11 @@ public static string Generate(int numWords, string separator = " ", bool crypto var randIndex = RandomInteger(0, Words.Length, crypto); words.Add(Words[randIndex]); } + + if(capital) + { + words[0] = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(words[0]); + } return string.Join(separator, words); }