From 95e97cf96b3305e493f1a3535307a2f99ca046d5 Mon Sep 17 00:00:00 2001 From: tj81 Date: Fri, 29 May 2026 12:14:40 +0200 Subject: [PATCH] Fix authentication failure after LHM restart caused by double-encoding of stored web-server password. (#2390) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow closing of AuthForm via OK without always resetting the existing password. Co-authored-by: Tobias Jüttner --- LibreHardwareMonitor.Windows.Forms/UI/AuthForm.cs | 7 +++++-- LibreHardwareMonitor.Windows.Forms/UI/MainForm.cs | 2 +- .../Utilities/HttpServer.cs | 11 +++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/LibreHardwareMonitor.Windows.Forms/UI/AuthForm.cs b/LibreHardwareMonitor.Windows.Forms/UI/AuthForm.cs index acc7b28..45cdd64 100644 --- a/LibreHardwareMonitor.Windows.Forms/UI/AuthForm.cs +++ b/LibreHardwareMonitor.Windows.Forms/UI/AuthForm.cs @@ -33,7 +33,10 @@ public partial class AuthForm : Form private void HttpAuthOkButton_Click(object sender, EventArgs e) { _parent.Server.UserName = httpAuthUsernameTextBox.Text; - _parent.Server.Password = httpAuthPasswordTextBox.Text; + if (!string.IsNullOrWhiteSpace(httpAuthPasswordTextBox.Text)) + { + _parent.Server.SetPassword(httpAuthPasswordTextBox.Text); + } _parent.Server.AuthEnabled = enableHTTPAuthCheckBox.Checked; _parent.AuthWebServerMenuItemChecked = _parent.Server.AuthEnabled; Close(); @@ -43,4 +46,4 @@ public partial class AuthForm : Form { httpAuthUsernameTextBox.Enabled = httpAuthPasswordTextBox.Enabled = enableHTTPAuthCheckBox.Checked; } -} \ No newline at end of file +} diff --git a/LibreHardwareMonitor.Windows.Forms/UI/MainForm.cs b/LibreHardwareMonitor.Windows.Forms/UI/MainForm.cs index f33c28c..a4aff93 100644 --- a/LibreHardwareMonitor.Windows.Forms/UI/MainForm.cs +++ b/LibreHardwareMonitor.Windows.Forms/UI/MainForm.cs @@ -964,7 +964,7 @@ public sealed partial class MainForm : Form _settings.SetValue("listenerPort", Server.ListenerPort); _settings.SetValue("authenticationEnabled", Server.AuthEnabled); _settings.SetValue("authenticationUserName", Server.UserName); - _settings.SetValue("authenticationPassword", Server.Password); + _settings.SetValue("authenticationPassword", Server.PasswordSHA256); string fileName = Path.ChangeExtension(Application.ExecutablePath, ".config"); diff --git a/LibreHardwareMonitor.Windows.Forms/Utilities/HttpServer.cs b/LibreHardwareMonitor.Windows.Forms/Utilities/HttpServer.cs index 391c251..76e291d 100644 --- a/LibreHardwareMonitor.Windows.Forms/Utilities/HttpServer.cs +++ b/LibreHardwareMonitor.Windows.Forms/Utilities/HttpServer.cs @@ -35,7 +35,7 @@ public class HttpServer private Task _listenerTask; private CancellationTokenSource _cts; - public HttpServer(Node node, IElement rootElement, string ip, int port, bool authEnabled = false, string userName = "", string password = "") + public HttpServer(Node node, IElement rootElement, string ip, int port, bool authEnabled = false, string userName = "", string passwordSHA256 = "") { _root = node; _rootElement = rootElement; @@ -43,7 +43,7 @@ public class HttpServer ListenerPort = port; AuthEnabled = authEnabled; UserName = userName; - Password = password; + PasswordSHA256 = passwordSHA256; try { @@ -74,10 +74,9 @@ public class HttpServer public int ListenerPort { get; set; } - public string Password + public void SetPassword(string plainPassword) { - get { return PasswordSHA256; } - set { PasswordSHA256 = ComputeSHA256(value); } + PasswordSHA256 = ComputeSHA256(plainPassword); } public bool PlatformNotSupported @@ -87,7 +86,7 @@ public class HttpServer public string UserName { get; set; } - private string PasswordSHA256 { get; set; } + public string PasswordSHA256 { get; set; } public bool StartHttpListener() {