using Microsoft.Win32; namespace NetworkTool.Client.Services; public sealed class PasswordStoreService { private const string RegistryPath = @"Software\NetworkTool"; private const string ValueName = "SavedPassword"; public string LoadPassword() { using var key = Registry.CurrentUser.OpenSubKey(RegistryPath, writable: false); return key?.GetValue(ValueName) as string ?? string.Empty; } public void SavePassword(string password) { using var key = Registry.CurrentUser.CreateSubKey(RegistryPath); key.SetValue(ValueName, password, RegistryValueKind.String); } public void ClearPassword() { using var key = Registry.CurrentUser.OpenSubKey(RegistryPath, writable: true); key?.DeleteValue(ValueName, throwOnMissingValue: false); } }