Skip to content

Commit

Permalink
Fixes an issue where a NullReferenceException occurrs when trying to …
Browse files Browse the repository at this point in the history
…set the store path and no policy has yet applied to the machine.
  • Loading branch information
ryannewington committed May 4, 2023
1 parent d3030ab commit bc2ad6b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/PasswordProtection/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -29,7 +29,7 @@ public bool Enabled
get => this.GetPolicyOrSetting<int>("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);
Expand All @@ -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;
}
}

Expand All @@ -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<T>(string name, T defaultValue)
Expand Down

0 comments on commit bc2ad6b

Please sign in to comment.