diff --git a/README.md b/README.md index e1feaec..f1cfc0b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ It uses the following configuration: - **Use Special Characters.** ``!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~``. Default `true`. - **Exclude Look-Alike characters.** It will avoid using two character that look similar, like `O` and `0`. Default `false`. - **Must occur at most Once.** It will prevent characters from appearing more than once. Default `false`. +- **Characters to Exclude.** Any character included in the text field will be excluded from the generated password. +- **Custom Pattern.** Allows to use a custom defined password generation pattern. Refer to the section *Generating Passwords that Follow Rules* of [KeePass Password Generator](https://keepass.info/help/base/pwgenerator.html) documentation. + - ***Note***: Using a custom pattern will override all the previous configuration. Check [KeePass Password Generator](https://keepass.info/help/base/pwgenerator.html) help site for more information. diff --git a/StreamDeck-KeePass/StreamDeck-KeePass/KeePassGenerate.cs b/StreamDeck-KeePass/StreamDeck-KeePass/KeePassGenerate.cs index 5a5d270..825e1c5 100644 --- a/StreamDeck-KeePass/StreamDeck-KeePass/KeePassGenerate.cs +++ b/StreamDeck-KeePass/StreamDeck-KeePass/KeePassGenerate.cs @@ -1,13 +1,10 @@ using BarRaider.SdTools; using KeePassLib.Cryptography.PasswordGenerator; -using KeePassLib.Keys; using KeePassLib.Security; -using KeePassLib.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using streamdeck_keepass; using System; -using System.Linq; using System.Threading.Tasks; namespace StreamDeck_KeePass @@ -27,7 +24,9 @@ public static PluginSettings CreateDefaultSettings() UseDigits = true, UsePunctuation = true, UseBrackets = true, - UseSpecial = true + UseSpecial = true, + ExcludeCharacters = string.Empty, + CustomPattern = string.Empty }; return instance; } @@ -58,6 +57,12 @@ public static PluginSettings CreateDefaultSettings() [JsonProperty(PropertyName = "mustOccurAtMostOnce")] public bool MustOccurAtMostOnce { get; set; } + + [JsonProperty(PropertyName = "excludeCharacters")] + public string ExcludeCharacters { get; set; } + + [JsonProperty(PropertyName = "customPattern")] + public string CustomPattern { get; set; } } #region Private Members @@ -101,7 +106,15 @@ public override void KeyPressed(KeyPayload payload) profile.ExcludeLookAlike = settings.ExcludeLookAlike; profile.Length = (uint)settings.Length; profile.NoRepeatingCharacters = settings.MustOccurAtMostOnce; - + profile.ExcludeCharacters = settings.ExcludeCharacters; + + if (!string.IsNullOrEmpty(settings.CustomPattern)) + { + profile.GeneratorType = PasswordGeneratorType.Pattern; + profile.PatternPermutePassword = true; + profile.Pattern = settings.CustomPattern; + } + PwGenerator.Generate(out pw, profile, null, new CustomPwGeneratorPool()); if (pw.IsEmpty) diff --git a/StreamDeck-KeePass/StreamDeck-KeePass/PropertyInspector/KeePassGeneratePI.html b/StreamDeck-KeePass/StreamDeck-KeePass/PropertyInspector/KeePassGeneratePI.html index dd88668..169b461 100644 --- a/StreamDeck-KeePass/StreamDeck-KeePass/PropertyInspector/KeePassGeneratePI.html +++ b/StreamDeck-KeePass/StreamDeck-KeePass/PropertyInspector/KeePassGeneratePI.html @@ -52,6 +52,14 @@ +