From 762760af2f204874300f9c727549a38e1db5ff36 Mon Sep 17 00:00:00 2001 From: Schmitti91 Date: Sat, 27 Jan 2024 20:55:12 +0100 Subject: [PATCH] Adding the configuration capability for the Credentials page through the Windows Registry. --- mRemoteNG/App/Info/WindowsRegistryInfo.cs | 3 + .../Registry/CommonRegistrySettings.cs | 36 +++-- .../Registry/OptRegistryCredentialsPage.cs | 77 +++++++++ .../Registry/OptRegistryUpdatesPage.cs | 3 - mRemoteNG/Security/SaveFilter.cs | 8 +- mRemoteNG/UI/Forms/FrmExport.Designer.cs | 15 +- .../OptionsPages/CredentialsPage.Designer.cs | 153 +++++++++++++----- .../UI/Forms/OptionsPages/CredentialsPage.cs | 144 ++++++++++++++++- 8 files changed, 368 insertions(+), 71 deletions(-) create mode 100644 mRemoteNG/Config/Settings/Registry/OptRegistryCredentialsPage.cs diff --git a/mRemoteNG/App/Info/WindowsRegistryInfo.cs b/mRemoteNG/App/Info/WindowsRegistryInfo.cs index 0ecd22a1..47f3d1e5 100644 --- a/mRemoteNG/App/Info/WindowsRegistryInfo.cs +++ b/mRemoteNG/App/Info/WindowsRegistryInfo.cs @@ -12,6 +12,9 @@ namespace mRemoteNG.App.Info #endregion #region subkey location parameters + // Credential + public const string CredentialSubkey = RootKey + "\\Credentials"; // Registry subkey for general credential settings + public const string CredentialOptionsSubkey = RootKey + "\\Credentials\\Options"; // Registry subkey for credential options within the credential settings // Updates public const string UpdateSubkey = RootKey + "\\Updates"; // Registry subkey for general update settings diff --git a/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs b/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs index 17199b8f..a1aa53e4 100644 --- a/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs +++ b/mRemoteNG/Config/Settings/Registry/CommonRegistrySettings.cs @@ -15,7 +15,7 @@ namespace mRemoteNG.Config.Settings.Registry private static readonly RegistryHive _Hive = WindowsRegistryInfo.Hive; private const string __Update = WindowsRegistryInfo.UpdateSubkey; - //private const string __Credential = WindowsRegistryInfo.CredentialSubkey; + private const string __Credential = WindowsRegistryInfo.CredentialSubkey; #region general update registry settings /// @@ -23,7 +23,6 @@ namespace mRemoteNG.Config.Settings.Registry /// /// /// Default value is true, which allows check for updates. - /// If the registry key is set to true, no action will be taken because the key is not needed. /// public static bool AllowCheckForUpdates { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdates), true); @@ -32,8 +31,6 @@ namespace mRemoteNG.Config.Settings.Registry /// /// /// Default value is true, which allows check for updates automaticaly. - /// If the registry key is set to true, no action will be taken because the key is not needed. - /// Important: If AllowCheckForUpdates is false, the default for this value (AllowCheckForUpdatesAutomatical) is also false, manual update checks are disabled. /// public static bool AllowCheckForUpdatesAutomatical { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdatesAutomatical), AllowCheckForUpdates); @@ -42,21 +39,40 @@ namespace mRemoteNG.Config.Settings.Registry /// /// /// The default value is true, enabling the manual check for updates. - /// If the registry key is set to true, no action will be taken because the key is not needed. - /// Important: If AllowCheckForUpdates is false, the default for this value (AllowCheckForUpdatesManual) is also false, manual update checks are disabled. /// public static bool AllowCheckForUpdatesManual { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowCheckForUpdatesManual), AllowCheckForUpdates); /// /// Specifies whether a question about checking for updates is displayed at startup. /// - /// - /// Important: If the registry entry is set to true, a popup will appear every time you start - /// public static bool AllowPromptForUpdatesPreference { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Update, nameof(AllowPromptForUpdatesPreference), AllowCheckForUpdates); #endregion + #region general credential registry settings + /// + /// Setting that indicates whether exporting passwords is allowed. + /// + public static bool AllowExportPasswords { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Credential, nameof(AllowExportPasswords), true); - + /// + /// Setting that indicates whether exporting usernames is allowed. + /// + public static bool AllowExportUsernames { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Credential, nameof(AllowExportUsernames), true); + + /// + /// Setting that indicates whether saving passwords is allowed. + /// + public static bool AllowSavePasswords { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Credential, nameof(AllowSavePasswords), true); + + /// + /// Setting that indicates whether saving usernames is allowed. + /// + public static bool AllowSaveUsernames { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Credential, nameof(AllowSaveUsernames), true); + + /// + /// Setting that indicates whether modifying credential settings is allowed. + /// + public static bool AllowModifyCredentialSettings { get; } = _WindowsRegistry.GetBoolValue(_Hive, __Credential, nameof(AllowModifyCredentialSettings), true); + #endregion } } \ No newline at end of file diff --git a/mRemoteNG/Config/Settings/Registry/OptRegistryCredentialsPage.cs b/mRemoteNG/Config/Settings/Registry/OptRegistryCredentialsPage.cs new file mode 100644 index 00000000..ee79cbff --- /dev/null +++ b/mRemoteNG/Config/Settings/Registry/OptRegistryCredentialsPage.cs @@ -0,0 +1,77 @@ +using System.Runtime.Versioning; +using Microsoft.Win32; +using mRemoteNG.App.Info; +using mRemoteNG.Tools.WindowsRegistry; + +namespace mRemoteNG.Config.Settings.Registry +{ + [SupportedOSPlatform("windows")] + /// Static utility class that provides access to and management of registry settings on the local machine. + /// It abstracts complex registry operations and centralizes the handling of various registry keys. + /// Benefits: Simplified code, enhances maintainability, and ensures consistency. #ReadOnly + public sealed partial class OptRegistryCredentialsPage : WindowsRegistryAdvanced + { + #region option page credential registry settings + /// + /// Specifies the radio button is set to none, windows or custom on the credentials page. + /// + /// + /// When set to noinfo or windows, WindowsCredentials and CustomCredentials are not evaluated and disabled. + /// + public WindowsRegistryKeyString UseCredentials { get; } + + /// + /// Specifies the user set via API as the default username. + /// + /// + /// Only avaiable if UseCredentials is set to custom! + /// + public WindowsRegistryKeyString UserViaAPIDefault { get; } + + /// + /// Specifies the default username. + /// + /// + /// Only avaiable if UseCredentials is set to custom! + /// + public WindowsRegistryKeyString DefaultUsername { get; } + + /// + /// Specifies the default password. + /// + /// + /// Only avaiable if UseCredentials is set to custom! + /// + //public WindowsRegistryKeyString DefaultPassword { get; } + + /// + /// Specifies the default domain. + /// + /// + /// Only avaiable if UseCredentials is set to custom! + /// + public WindowsRegistryKeyString DefaultDomain { get; } + #endregion + + public OptRegistryCredentialsPage() + { + RegistryHive hive = WindowsRegistryInfo.Hive; + string subKey = WindowsRegistryInfo.CredentialOptionsSubkey; + + UseCredentials = GetStringValidated(hive, subKey, nameof(UseCredentials), + new string[] { + "noinfo", + "windows", + "custom" + }, true + ); + + UserViaAPIDefault = GetString(hive, subKey, nameof(UserViaAPIDefault), null); + DefaultUsername = GetString(hive, subKey, nameof(DefaultUsername), null); + //Currently not supported, but needed for configuration... + //DefaultPassword = GetPassword(hive, subKey, nameof(DefaultPassword)); + + DefaultDomain = GetString(hive, subKey, nameof(DefaultDomain), null); + } + } +} \ No newline at end of file diff --git a/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs b/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs index a817c7d8..3c50810a 100644 --- a/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs +++ b/mRemoteNG/Config/Settings/Registry/OptRegistryUpdatesPage.cs @@ -52,9 +52,6 @@ namespace mRemoteNG.Config.Settings.Registry /// /// Specifies the authentication password for the proxy. /// - /// - /// Please only store encrypted passwords in the registry. - /// //public string ProxyAuthPass { get; } public OptRegistryUpdatesPage() diff --git a/mRemoteNG/Security/SaveFilter.cs b/mRemoteNG/Security/SaveFilter.cs index db3a086f..82395e78 100644 --- a/mRemoteNG/Security/SaveFilter.cs +++ b/mRemoteNG/Security/SaveFilter.cs @@ -1,12 +1,16 @@ +using mRemoteNG.Config.Settings.Registry; +using System.Runtime.Versioning; + namespace mRemoteNG.Security { + [SupportedOSPlatform("windows")] public class SaveFilter { public SaveFilter(bool disableEverything = false) { if (disableEverything) return; - SaveUsername = true; - SavePassword = true; + SaveUsername = CommonRegistrySettings.AllowSaveUsernames; + SavePassword = CommonRegistrySettings.AllowSavePasswords; SaveDomain = true; SaveCredentialId = true; SaveInheritance = true; diff --git a/mRemoteNG/UI/Forms/FrmExport.Designer.cs b/mRemoteNG/UI/Forms/FrmExport.Designer.cs index 5951ff36..c51526cd 100644 --- a/mRemoteNG/UI/Forms/FrmExport.Designer.cs +++ b/mRemoteNG/UI/Forms/FrmExport.Designer.cs @@ -1,5 +1,6 @@  using System.Windows.Forms; +using mRemoteNG.Config.Settings.Registry; using mRemoteNG.UI.Controls; namespace mRemoteNG.UI.Forms @@ -72,27 +73,33 @@ namespace mRemoteNG.UI.Forms // this.chkUsername._mice = MrngCheckBox.MouseState.HOVER; this.chkUsername.AutoSize = true; - this.chkUsername.Checked = true; - this.chkUsername.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkUsername.Checked = CommonRegistrySettings.AllowExportUsernames; + this.chkUsername.CheckState = CommonRegistrySettings.AllowExportUsernames ? + System.Windows.Forms.CheckState.Checked : + System.Windows.Forms.CheckState.Unchecked; this.chkUsername.Location = new System.Drawing.Point(15, 32); this.chkUsername.Name = "chkUsername"; this.chkUsername.Size = new System.Drawing.Size(77, 17); this.chkUsername.TabIndex = 0; this.chkUsername.Text = "Username"; this.chkUsername.UseVisualStyleBackColor = true; + this.chkUsername.Enabled = CommonRegistrySettings.AllowExportUsernames; // // chkPassword // this.chkPassword._mice = MrngCheckBox.MouseState.HOVER; this.chkPassword.AutoSize = true; - this.chkPassword.Checked = true; - this.chkPassword.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkPassword.Checked = CommonRegistrySettings.AllowExportPasswords; + this.chkPassword.CheckState = CommonRegistrySettings.AllowExportPasswords ? + System.Windows.Forms.CheckState.Checked : + System.Windows.Forms.CheckState.Unchecked; this.chkPassword.Location = new System.Drawing.Point(15, 55); this.chkPassword.Name = "chkPassword"; this.chkPassword.Size = new System.Drawing.Size(75, 17); this.chkPassword.TabIndex = 1; this.chkPassword.Text = "Password"; this.chkPassword.UseVisualStyleBackColor = true; + this.chkPassword.Enabled = CommonRegistrySettings.AllowExportPasswords; // // chkDomain // diff --git a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs index 4a8c3d3c..f88641c7 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.Designer.cs @@ -29,6 +29,9 @@ private void InitializeComponent() { pnlDefaultCredentials = new System.Windows.Forms.Panel(); + pnlCredentialsSettingsPanel = new System.Windows.Forms.Panel(); + lblDefaultCredentials = new Controls.MrngLabel(); + radCredentialsWindows = new Controls.MrngRadioButton(); tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); txtCredentialsUserViaAPI = new Controls.MrngTextBox(); txtCredentialsUsername = new Controls.MrngTextBox(); @@ -38,26 +41,61 @@ lblCredentialsUsername = new Controls.MrngLabel(); lblCredentialsPassword = new Controls.MrngLabel(); lblCredentialsDomain = new Controls.MrngLabel(); - radCredentialsCustom = new Controls.MrngRadioButton(); - lblDefaultCredentials = new Controls.MrngLabel(); radCredentialsNoInfo = new Controls.MrngRadioButton(); - radCredentialsWindows = new Controls.MrngRadioButton(); + radCredentialsCustom = new Controls.MrngRadioButton(); + lblCredentialsAdminInfo = new System.Windows.Forms.Label(); + lblCredentialsGeneratorHelp = new Controls.MrngLabel(); + btnCredentialsGenerator = new System.Windows.Forms.Button(); + lblCredentialsGenerator = new Controls.MrngLabel(); + txtCredentialsGeneratorPsswd = new System.Windows.Forms.TextBox(); pnlDefaultCredentials.SuspendLayout(); + pnlCredentialsSettingsPanel.SuspendLayout(); tableLayoutPanel1.SuspendLayout(); SuspendLayout(); // // pnlDefaultCredentials // - pnlDefaultCredentials.Controls.Add(tableLayoutPanel1); - pnlDefaultCredentials.Controls.Add(radCredentialsCustom); - pnlDefaultCredentials.Controls.Add(lblDefaultCredentials); - pnlDefaultCredentials.Controls.Add(radCredentialsNoInfo); - pnlDefaultCredentials.Controls.Add(radCredentialsWindows); - pnlDefaultCredentials.Location = new System.Drawing.Point(3, 3); + pnlDefaultCredentials.Controls.Add(pnlCredentialsSettingsPanel); + pnlDefaultCredentials.Controls.Add(lblCredentialsAdminInfo); + pnlDefaultCredentials.Dock = System.Windows.Forms.DockStyle.Top; + pnlDefaultCredentials.Location = new System.Drawing.Point(0, 0); pnlDefaultCredentials.Name = "pnlDefaultCredentials"; - pnlDefaultCredentials.Size = new System.Drawing.Size(604, 200); + pnlDefaultCredentials.Size = new System.Drawing.Size(610, 416); pnlDefaultCredentials.TabIndex = 0; // + // pnlCredentialsSettingsPanel + // + pnlCredentialsSettingsPanel.Controls.Add(lblDefaultCredentials); + pnlCredentialsSettingsPanel.Controls.Add(radCredentialsWindows); + pnlCredentialsSettingsPanel.Controls.Add(tableLayoutPanel1); + pnlCredentialsSettingsPanel.Controls.Add(radCredentialsNoInfo); + pnlCredentialsSettingsPanel.Controls.Add(radCredentialsCustom); + pnlCredentialsSettingsPanel.Dock = System.Windows.Forms.DockStyle.Top; + pnlCredentialsSettingsPanel.Location = new System.Drawing.Point(0, 30); + pnlCredentialsSettingsPanel.Name = "pnlCredentialsSettingsPanel"; + pnlCredentialsSettingsPanel.Size = new System.Drawing.Size(610, 214); + pnlCredentialsSettingsPanel.TabIndex = 0; + // + // lblDefaultCredentials + // + lblDefaultCredentials.AutoSize = true; + lblDefaultCredentials.Location = new System.Drawing.Point(3, 0); + lblDefaultCredentials.Name = "lblDefaultCredentials"; + lblDefaultCredentials.Size = new System.Drawing.Size(279, 13); + lblDefaultCredentials.TabIndex = 0; + lblDefaultCredentials.Text = "For empty Username, Password or Domain fields use:"; + // + // radCredentialsWindows + // + radCredentialsWindows.AutoSize = true; + radCredentialsWindows.BackColor = System.Drawing.Color.Transparent; + radCredentialsWindows.Location = new System.Drawing.Point(6, 39); + radCredentialsWindows.Name = "radCredentialsWindows"; + radCredentialsWindows.Size = new System.Drawing.Size(252, 17); + radCredentialsWindows.TabIndex = 2; + radCredentialsWindows.Text = "my current credentials (windows logon info)"; + radCredentialsWindows.UseVisualStyleBackColor = false; + // // tableLayoutPanel1 // tableLayoutPanel1.ColumnCount = 2; @@ -71,7 +109,7 @@ tableLayoutPanel1.Controls.Add(lblCredentialsUsername, 0, 1); tableLayoutPanel1.Controls.Add(lblCredentialsPassword, 0, 2); tableLayoutPanel1.Controls.Add(lblCredentialsDomain, 0, 3); - tableLayoutPanel1.Location = new System.Drawing.Point(23, 85); + tableLayoutPanel1.Location = new System.Drawing.Point(26, 85); tableLayoutPanel1.Name = "tableLayoutPanel1"; tableLayoutPanel1.RowCount = 3; tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); @@ -113,7 +151,6 @@ txtCredentialsPassword.Name = "txtCredentialsPassword"; txtCredentialsPassword.Size = new System.Drawing.Size(166, 22); txtCredentialsPassword.TabIndex = 7; - txtCredentialsPassword.UseSystemPasswordChar = true; // // txtCredentialsDomain // @@ -170,33 +207,12 @@ lblCredentialsDomain.Text = "Domain:"; lblCredentialsDomain.TextAlign = System.Drawing.ContentAlignment.TopRight; // - // radCredentialsCustom - // - radCredentialsCustom.AutoSize = true; - radCredentialsCustom.BackColor = System.Drawing.Color.Transparent; - radCredentialsCustom.Location = new System.Drawing.Point(3, 62); - radCredentialsCustom.Name = "radCredentialsCustom"; - radCredentialsCustom.Size = new System.Drawing.Size(98, 17); - radCredentialsCustom.TabIndex = 3; - radCredentialsCustom.Text = "the following:"; - radCredentialsCustom.UseVisualStyleBackColor = false; - radCredentialsCustom.CheckedChanged += radCredentialsCustom_CheckedChanged; - // - // lblDefaultCredentials - // - lblDefaultCredentials.AutoSize = true; - lblDefaultCredentials.Location = new System.Drawing.Point(0, 0); - lblDefaultCredentials.Name = "lblDefaultCredentials"; - lblDefaultCredentials.Size = new System.Drawing.Size(279, 13); - lblDefaultCredentials.TabIndex = 0; - lblDefaultCredentials.Text = "For empty Username, Password or Domain fields use:"; - // // radCredentialsNoInfo // radCredentialsNoInfo.AutoSize = true; radCredentialsNoInfo.BackColor = System.Drawing.Color.Transparent; radCredentialsNoInfo.Checked = true; - radCredentialsNoInfo.Location = new System.Drawing.Point(3, 16); + radCredentialsNoInfo.Location = new System.Drawing.Point(6, 16); radCredentialsNoInfo.Name = "radCredentialsNoInfo"; radCredentialsNoInfo.Size = new System.Drawing.Size(103, 17); radCredentialsNoInfo.TabIndex = 1; @@ -204,16 +220,58 @@ radCredentialsNoInfo.Text = "no information"; radCredentialsNoInfo.UseVisualStyleBackColor = false; // - // radCredentialsWindows + // radCredentialsCustom // - radCredentialsWindows.AutoSize = true; - radCredentialsWindows.BackColor = System.Drawing.Color.Transparent; - radCredentialsWindows.Location = new System.Drawing.Point(3, 39); - radCredentialsWindows.Name = "radCredentialsWindows"; - radCredentialsWindows.Size = new System.Drawing.Size(252, 17); - radCredentialsWindows.TabIndex = 2; - radCredentialsWindows.Text = "my current credentials (windows logon info)"; - radCredentialsWindows.UseVisualStyleBackColor = false; + radCredentialsCustom.AutoSize = true; + radCredentialsCustom.BackColor = System.Drawing.Color.Transparent; + radCredentialsCustom.Location = new System.Drawing.Point(6, 62); + radCredentialsCustom.Name = "radCredentialsCustom"; + radCredentialsCustom.Size = new System.Drawing.Size(98, 17); + radCredentialsCustom.TabIndex = 3; + radCredentialsCustom.Text = "the following:"; + radCredentialsCustom.UseVisualStyleBackColor = false; + radCredentialsCustom.CheckedChanged += radCredentialsCustom_CheckedChanged; + // + // lblCredentialsAdminInfo + // + lblCredentialsAdminInfo.BackColor = System.Drawing.SystemColors.ControlLight; + lblCredentialsAdminInfo.Dock = System.Windows.Forms.DockStyle.Top; + lblCredentialsAdminInfo.ForeColor = System.Drawing.SystemColors.ControlText; + lblCredentialsAdminInfo.Location = new System.Drawing.Point(0, 0); + lblCredentialsAdminInfo.Name = "lblCredentialsAdminInfo"; + lblCredentialsAdminInfo.Padding = new System.Windows.Forms.Padding(0, 2, 0, 0); + lblCredentialsAdminInfo.Size = new System.Drawing.Size(610, 30); + lblCredentialsAdminInfo.TabIndex = 0; + lblCredentialsAdminInfo.Text = "Some settings are configured by your Administrator. Please contact your administrator for more information."; + lblCredentialsAdminInfo.Visible = false; + // + // lblCredentialsGeneratorHelp + // + lblCredentialsGeneratorHelp.Location = new System.Drawing.Point(0, 0); + lblCredentialsGeneratorHelp.Name = "lblCredentialsGeneratorHelp"; + lblCredentialsGeneratorHelp.Size = new System.Drawing.Size(100, 23); + lblCredentialsGeneratorHelp.TabIndex = 0; + // + // btnCredentialsGenerator + // + btnCredentialsGenerator.Location = new System.Drawing.Point(0, 0); + btnCredentialsGenerator.Name = "btnCredentialsGenerator"; + btnCredentialsGenerator.Size = new System.Drawing.Size(75, 23); + btnCredentialsGenerator.TabIndex = 0; + // + // lblCredentialsGenerator + // + lblCredentialsGenerator.Location = new System.Drawing.Point(0, 0); + lblCredentialsGenerator.Name = "lblCredentialsGenerator"; + lblCredentialsGenerator.Size = new System.Drawing.Size(100, 23); + lblCredentialsGenerator.TabIndex = 0; + // + // txtCredentialsGeneratorPsswd + // + txtCredentialsGeneratorPsswd.Location = new System.Drawing.Point(0, 0); + txtCredentialsGeneratorPsswd.Name = "txtCredentialsGeneratorPsswd"; + txtCredentialsGeneratorPsswd.Size = new System.Drawing.Size(100, 23); + txtCredentialsGeneratorPsswd.TabIndex = 0; // // CredentialsPage // @@ -224,7 +282,8 @@ Name = "CredentialsPage"; Size = new System.Drawing.Size(610, 490); pnlDefaultCredentials.ResumeLayout(false); - pnlDefaultCredentials.PerformLayout(); + pnlCredentialsSettingsPanel.ResumeLayout(false); + pnlCredentialsSettingsPanel.PerformLayout(); tableLayoutPanel1.ResumeLayout(false); tableLayoutPanel1.PerformLayout(); ResumeLayout(false); @@ -245,5 +304,11 @@ internal Controls.MrngTextBox txtCredentialsUsername; internal Controls.MrngLabel lblCredentialsDomain; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + internal System.Windows.Forms.Label lblCredentialsAdminInfo; + internal System.Windows.Forms.Panel pnlCredentialsSettingsPanel; + internal Controls.MrngLabel lblCredentialsGenerator; + internal System.Windows.Forms.TextBox txtCredentialsGeneratorPsswd; + internal System.Windows.Forms.Button btnCredentialsGenerator; + internal Controls.MrngLabel lblCredentialsGeneratorHelp; } } diff --git a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs index 3fbbbda0..465a3ad1 100644 --- a/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs +++ b/mRemoteNG/UI/Forms/OptionsPages/CredentialsPage.cs @@ -4,12 +4,19 @@ using mRemoteNG.Properties; using mRemoteNG.Security.SymmetricEncryption; using mRemoteNG.Resources.Language; using System.Runtime.Versioning; +using mRemoteNG.Config.Settings.Registry; namespace mRemoteNG.UI.Forms.OptionsPages { [SupportedOSPlatform("windows")] public sealed partial class CredentialsPage : OptionsPage { + #region Private Fields + private readonly OptRegistryCredentialsPage _RegistrySettings = new(); + private bool _pageEnabled = true; + + #endregion + public CredentialsPage() { InitializeComponent(); @@ -33,10 +40,13 @@ namespace mRemoteNG.UI.Forms.OptionsPages lblCredentialsUsername.Text = Language.Username; lblCredentialsPassword.Text = Language.Password; lblCredentialsDomain.Text = Language.Domain; + lblCredentialsAdminInfo.Text = Language.OptionsAdminInfo; } public override void LoadSettings() { + if (!_pageEnabled) { return; } + // ReSharper disable once SwitchStatementMissingSomeCases switch (Properties.OptionsCredentialsPage.Default.EmptyCredentials) { @@ -80,16 +90,134 @@ namespace mRemoteNG.UI.Forms.OptionsPages Properties.OptionsCredentialsPage.Default.UserViaAPIDefault = txtCredentialsUserViaAPI.Text; } + public override void LoadRegistrySettings() + { + if (!CommonRegistrySettings.AllowModifyCredentialSettings) + { + DisablePage(); + return; + } + + if (_RegistrySettings.UseCredentials.IsKeyPresent) + { + Properties.OptionsCredentialsPage.Default.EmptyCredentials = _RegistrySettings.UseCredentials.Value; + + switch (Properties.OptionsCredentialsPage.Default.EmptyCredentials) + { + case "noinfo": + DisableControl(radCredentialsWindows); + DisableControl(radCredentialsCustom); + break; + case "windows": + DisableControl(radCredentialsNoInfo); + DisableControl(radCredentialsCustom); + break; + case "custom": + DisableControl(radCredentialsNoInfo); + DisableControl(radCredentialsWindows); + break; + } + } + + if (_RegistrySettings.UseCredentials.Value != "custom") { return; } + + + if (!CommonRegistrySettings.AllowSaveUsernames) + { + Properties.OptionsCredentialsPage.Default.DefaultUsername = ""; + DisableControl(txtCredentialsUsername); + } + else if (_RegistrySettings.DefaultUsername.IsKeyPresent) + { + Properties.OptionsCredentialsPage.Default.DefaultUsername = _RegistrySettings.DefaultUsername.Value; + DisableControl(txtCredentialsUsername); + } + + if (!CommonRegistrySettings.AllowSavePasswords) + { + Properties.OptionsCredentialsPage.Default.DefaultPassword = ""; + DisableControl(txtCredentialsPassword); + } + //else if (_RegistrySettings.DefaultPassword.IsKeyPresent) + //{ + // Properties.OptionsCredentialsPage.Default.DefaultPassword = _RegistrySettings.DefaultPassword.Value; + // DisableControl(txtCredentialsPassword); + //} + + if (_RegistrySettings.DefaultDomain.IsKeyPresent) + { + Properties.OptionsCredentialsPage.Default.DefaultDomain = _RegistrySettings.DefaultDomain.Value; + DisableControl(txtCredentialsDomain); + } + + if (!CommonRegistrySettings.AllowSaveUsernames) + { + Properties.OptionsCredentialsPage.Default.UserViaAPIDefault = ""; + DisableControl(txtCredentialsUserViaAPI); + } + else if (_RegistrySettings.UserViaAPIDefault.IsKeyPresent) + { + Properties.OptionsCredentialsPage.Default.UserViaAPIDefault = _RegistrySettings.UserViaAPIDefault.Value; + DisableControl(txtCredentialsUserViaAPI); + } + + lblCredentialsAdminInfo.Visible = ShowAdministratorInfo(); + } + + public override bool ShowAdministratorInfo() + { + return !CommonRegistrySettings.AllowModifyCredentialSettings + || !CommonRegistrySettings.AllowExportPasswords + || !CommonRegistrySettings.AllowExportUsernames + || !CommonRegistrySettings.AllowSavePasswords + || !CommonRegistrySettings.AllowSaveUsernames + || _RegistrySettings.DefaultUsername.IsKeyPresent + //|| _RegistrySettings.DefaultPassword.IsKeyPresent + || _RegistrySettings.DefaultDomain.IsKeyPresent + || _RegistrySettings.UserViaAPIDefault.IsKeyPresent; + } + private void radCredentialsCustom_CheckedChanged(object sender, EventArgs e) { - lblCredentialsUsername.Enabled = radCredentialsCustom.Checked; - lblCredentialsPassword.Enabled = radCredentialsCustom.Checked; - lblCredentialsDomain.Enabled = radCredentialsCustom.Checked; - txtCredentialsUsername.Enabled = radCredentialsCustom.Checked; - txtCredentialsPassword.Enabled = radCredentialsCustom.Checked; - txtCredentialsDomain.Enabled = radCredentialsCustom.Checked; - txtCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; - lblCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; + if (!_RegistrySettings.DefaultUsername.IsKeyPresent && CommonRegistrySettings.AllowSaveUsernames) + { + lblCredentialsUsername.Enabled = radCredentialsCustom.Checked; + txtCredentialsUsername.Enabled = radCredentialsCustom.Checked; + } + + if (/*!_RegistrySettings.DefaultPassword.IsKeyPresent &&*/ CommonRegistrySettings.AllowSavePasswords) + { + lblCredentialsPassword.Enabled = radCredentialsCustom.Checked; + txtCredentialsPassword.Enabled = radCredentialsCustom.Checked; + } + + if (!_RegistrySettings.DefaultDomain.IsKeyPresent) + { + lblCredentialsDomain.Enabled = radCredentialsCustom.Checked; + txtCredentialsDomain.Enabled = radCredentialsCustom.Checked; + } + + if (!_RegistrySettings.UserViaAPIDefault.IsKeyPresent) + { + lblCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; + txtCredentialsUserViaAPI.Enabled = radCredentialsCustom.Checked; + } + } + + public override void DisablePage() + { + Properties.OptionsCredentialsPage.Default.EmptyCredentials = "noinfo"; + //radCredentialsNoInfo.Enabled = false; + radCredentialsWindows.Enabled = false; + radCredentialsCustom.Enabled = false; + + txtCredentialsUsername.Enabled = false; + txtCredentialsPassword.Enabled = false; + txtCredentialsDomain.Enabled = false; + txtCredentialsUserViaAPI.Enabled = false; + + lblCredentialsAdminInfo.Visible = true; + _pageEnabled = false; } } } \ No newline at end of file