diff --git a/src/PasswordProtection/Settings.cs b/src/PasswordProtection/Settings.cs index 6f60439..0fda870 100644 --- a/src/PasswordProtection/Settings.cs +++ b/src/PasswordProtection/Settings.cs @@ -19,7 +19,7 @@ public string StorePath throw new DirectoryNotFoundException($"The path {value} was not found"); } - var settingsKey = this.hklm.OpenSubKey("Software\\Lithnet\\PasswordFilter", true); + var settingsKey = this.hklm.CreateSubKey("Software\\Lithnet\\PasswordFilter", true); settingsKey.SetValue("Store", value); } } @@ -29,7 +29,7 @@ public bool Enabled get => this.GetPolicyOrSetting("Disabled", 0) == 0; set { - var settingsKey = this.hklm.OpenSubKey("Software\\Lithnet\\PasswordFilter", true); + var settingsKey = this.hklm.CreateSubKey("Software\\Lithnet\\PasswordFilter", true); if (value) { settingsKey.DeleteValue("Disabled", false); @@ -49,7 +49,7 @@ public bool IsFilterRegistered var values = key?.GetValue("Notification Packages") as string[]; - return values.Contains("lithnetpwdf", StringComparer.OrdinalIgnoreCase); + return values?.Contains("lithnetpwdf", StringComparer.OrdinalIgnoreCase) ?? false; } } @@ -67,7 +67,7 @@ private bool IsPolicyEnforced(string setting) { var policyKey = this.hklm.OpenSubKey("Software\\Policies\\Lithnet\\PasswordFilter", false); - return policyKey.GetValue(setting, null) != null; + return policyKey?.GetValue(setting, null) != null; } private T GetPolicyOrSetting(string name, T defaultValue)