Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update TOTP create to hide name input by default in web app (#2216)
Leendert de Borst96964ba17967
diff --git a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razorindex b4a193ada..84550bcb7 100644--- a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor+++ b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor@@ -53,16 +53,36 @@}</div><p class="mb-4 text-sm text-gray-500 dark:text-gray-400">@Localizer["TotpInstructions"]</p>- <div class="mb-4">- <label for="totp-name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@Localizer["NameOptionalLabel"]</label>- <InputTextOnInput id="totp-name" @bind-Value="NewTotpCode.Name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white" />- <ValidationMessage For="@(() => NewTotpCode.Name)" class="text-red-600 dark:text-red-400 text-sm mt-1" />- </div><div class="mb-4"><label for="totp-secret" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@Localizer["SecretKeyLabel"]</label><InputTextOnInput id="totp-secret" @bind-Value="NewTotpCode.SecretKey" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white" placeholder="@Localizer["SecretKeyPlaceholder"]" /><ValidationMessage For="@(() => NewTotpCode.SecretKey)" class="text-red-600 dark:text-red-400 text-sm mt-1" /></div>+ @* Name is optional and hidden by default; revealed on demand since most codes don't need one. *@+ @if (ShowNameField)+ {+ <div class="mb-4">+ <div class="flex items-center justify-between mb-2">+ <label for="totp-name" class="text-sm font-medium text-gray-900 dark:text-white">@Localizer["NameOptionalLabel"]</label>+ <button id="remove-totp-name" type="button" @onclick="HideNameField" class="w-5 h-5 flex items-center justify-center text-gray-300 hover:text-red-400 dark:text-gray-500 dark:hover:text-red-400 transition-colors" title="@SharedLocalizer["Remove"]">+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <line x1="18" y1="6" x2="6" y2="18"/>+ <line x1="6" y1="6" x2="18" y2="18"/>+ </svg>+ </button>+ </div>+ <InputTextOnInput id="totp-name" @bind-Value="NewTotpCode.Name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white" />+ <ValidationMessage For="@(() => NewTotpCode.Name)" class="text-red-600 dark:text-red-400 text-sm mt-1" />+ </div>+ }+ else+ {+ <div class="mb-4">+ <button id="add-totp-name" type="button" @onclick="() => ShowNameField = true" class="text-sm font-medium text-primary-700 hover:text-primary-800 dark:text-primary-500 dark:hover:text-primary-400">+ @Localizer["AddNameButton"]+ </button>+ </div>+ }<div class="flex justify-end"><button id="save-totp-code" type="submit" class="text-white bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">@Localizer["SaveButton"]@@ -78,7 +98,7 @@<div class="p-2 ps-3 pe-3 bg-gray-50 border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600"><div class="flex justify-between items-center gap-2"><div class="flex items-center flex-1">- <h4 class="text-sm font-medium text-gray-900 dark:text-white">@totpCode.Name</h4>+ <h4 class="text-sm font-medium text-gray-900 dark:text-white">@(string.IsNullOrEmpty(totpCode.Name) ? SharedLocalizer["TotpDefaultName"] : totpCode.Name)</h4></div><div class="flex items-center gap-2"><div class="flex flex-col items-end">@@ -111,11 +131,6 @@@if (EditingTotpCode != null){<div class="space-y-3">- <div>- <label class="block text-sm font-medium text-gray-900 dark:text-white mb-2">@Localizer["NameOptionalLabel"]</label>- <input type="text" @bind="EditName" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:text-white" placeholder="@Localizer["NameOptionalLabel"]" />- </div>-<div><div class="flex items-center justify-between mb-2"><label class="text-sm font-medium text-gray-900 dark:text-white">@Localizer["SecretKeyLabel"]</label>@@ -134,6 +149,29 @@}</div>+ @* Name is optional; hidden by default unless a custom name was set. *@+ @if (ShowEditNameField)+ {+ <div>+ <div class="flex items-center justify-between mb-2">+ <label class="text-sm font-medium text-gray-900 dark:text-white">@Localizer["NameOptionalLabel"]</label>+ <button type="button" @onclick="HideEditNameField" class="w-5 h-5 flex items-center justify-center text-gray-300 hover:text-red-400 dark:text-gray-500 dark:hover:text-red-400 transition-colors" title="@SharedLocalizer["Remove"]">+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <line x1="18" y1="6" x2="6" y2="18"/>+ <line x1="6" y1="6" x2="18" y2="18"/>+ </svg>+ </button>+ </div>+ <input type="text" @bind="EditName" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:text-white" placeholder="@Localizer["NameOptionalLabel"]" />+ </div>+ }+ else+ {+ <button type="button" @onclick="() => ShowEditNameField = true" class="text-sm font-medium text-primary-700 hover:text-primary-800 dark:text-primary-500 dark:hover:text-primary-400">+ @Localizer["AddNameButton"]+ </button>+ }+<button type="button" @onclick="SaveEditedTotpCode" class="w-full text-white bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">@SharedLocalizer["Save"]</button>@@ -184,11 +222,13 @@public string? ItemUsername { get; set; }private bool IsAddFormVisible { get; set; } = false;+ private bool ShowNameField { get; set; } = false;private TotpCodeEdit NewTotpCode { get; set; } = new();private List<Guid> OriginalTotpCodeIds { get; set; } = [];private bool IsEditModalOpen { get; set; } = false;private TotpCode? EditingTotpCode { get; set; }private string EditName { get; set; } = string.Empty;+ private bool ShowEditNameField { get; set; } = false;private string EditSecret { get; set; } = string.Empty;private bool ShowQrCode { get; set; } = false;@@ -224,9 +264,19 @@private void ShowAddForm(){NewTotpCode = new TotpCodeEdit();+ ShowNameField = false;IsAddFormVisible = true;}+ /// <summary>+ /// Hides the optional name field again and clears any entered value.+ /// </summary>+ private void HideNameField()+ {+ NewTotpCode.Name = null;+ ShowNameField = false;+ }+/// <summary>/// Hides the add form./// </summary>@@ -254,7 +304,7 @@// Create a new TOTP code in memoryvar newTotpCode = NewTotpCode.ToEntity();- newTotpCode.Name = NewTotpCode.Name ?? "Authenticator";+ newTotpCode.Name = NewTotpCode.Name ?? string.Empty;// Add to the listTotpCodeList.Add(newTotpCode);@@ -316,7 +366,11 @@private void ShowEditModal(TotpCode totpCode){EditingTotpCode = totpCode;++ // Only reveal the name field when a name was actually set.EditName = totpCode.Name;+ ShowEditNameField = !string.IsNullOrEmpty(totpCode.Name);+EditSecret = totpCode.SecretKey;ShowQrCode = false;IsEditModalOpen = true;@@ -331,11 +385,22 @@IsEditModalOpen = false;EditingTotpCode = null;EditName = string.Empty;+ ShowEditNameField = false;EditSecret = string.Empty;ShowQrCode = false;StateHasChanged();}+ /// <summary>+ /// Hides the edit name field again and clears any entered value so the code+ /// falls back to the default name on save.+ /// </summary>+ private void HideEditNameField()+ {+ EditName = string.Empty;+ ShowEditNameField = false;+ }+/// <summary>/// Saves the edited TOTP code./// </summary>@@ -346,7 +411,8 @@var totpCodeToUpdate = TotpCodeList.FirstOrDefault(t => t.Id == EditingTotpCode.Id);if (totpCodeToUpdate != null){- totpCodeToUpdate.Name = EditName;+ // The name is optional; store it as-is (blank when the user left it empty).+ totpCodeToUpdate.Name = EditName?.Trim() ?? string.Empty;totpCodeToUpdate.SecretKey = EditSecret;totpCodeToUpdate.UpdatedAt = DateTime.UtcNow;}diff --git a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpViewer.razor b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpViewer.razorindex 51c811f67..1bac9cec0 100644--- a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpViewer.razor+++ b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpViewer.razor@@ -31,7 +31,7 @@<div class="p-2 ps-3 pe-3 bg-gray-50 border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600"><div class="flex justify-between items-center gap-2"><div class="flex items-center flex-1">- <h4 class="text-sm font-medium text-gray-900 dark:text-white">@totpCode.Name</h4>+ <h4 class="text-sm font-medium text-gray-900 dark:text-white">@(string.IsNullOrEmpty(totpCode.Name) ? SharedLocalizer["TotpDefaultName"] : totpCode.Name)</h4></div><div class="flex items-center gap-2"><div class="flex flex-col items-end">@@ -63,6 +63,8 @@@code {private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Components.TotpCodes.TotpViewer", "AliasVault.Client");+ private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");+/// <summary>/// The list of TOTP codes to display./// </summary>diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Components/TotpCodes/TotpCodes.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Components/TotpCodes/TotpCodes.en.resxindex 674045f33..307507f56 100644--- a/apps/server/AliasVault.Client/Resources/Components/Main/Components/TotpCodes/TotpCodes.en.resx+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Components/TotpCodes/TotpCodes.en.resx@@ -82,6 +82,10 @@<value>Name (optional)</value><comment>Label for optional name field</comment></data>+ <data name="AddNameButton" xml:space="preserve">+ <value>Add a name (optional)</value>+ <comment>Toggle button that reveals the optional name field in the add form</comment>+ </data><data name="SecretKeyLabel" xml:space="preserve"><value>Secret Key</value><comment>Label for secret key field</comment>diff --git a/apps/server/AliasVault.Client/Resources/SharedResources.en.resx b/apps/server/AliasVault.Client/Resources/SharedResources.en.resxindex ef7fc165c..3617a73e2 100644--- a/apps/server/AliasVault.Client/Resources/SharedResources.en.resx+++ b/apps/server/AliasVault.Client/Resources/SharedResources.en.resx@@ -135,6 +135,14 @@<value>Delete</value><comment>Button text for deleting an item</comment></data>+ <data name="Remove" xml:space="preserve">+ <value>Remove</value>+ <comment>Button text for removing an item</comment>+ </data>+ <data name="TotpDefaultName" xml:space="preserve">+ <value>Authenticator</value>+ <comment>Display-only fallback name shown for a TOTP code that has no name set</comment>+ </data><data name="Edit" xml:space="preserve"><value>Edit</value><comment>Button text for editing an item</comment>diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.cssindex 17861df20..4d58ddec3 100644--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css@@ -3120,6 +3120,11 @@ video {color: rgb(184 112 47 / var(--tw-text-opacity));}+.hover\:text-primary-800:hover {+ --tw-text-opacity: 1;+ color: rgb(154 93 38 / var(--tw-text-opacity));+}+.hover\:text-red-200:hover {--tw-text-opacity: 1;color: rgb(254 202 202 / var(--tw-text-opacity));diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/TotpTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/TotpTests.csindex a0e37ac5a..d4b296997 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/TotpTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/TotpTests.cs@@ -36,6 +36,8 @@ public class TotpTests : ClientPlaywrightTestawait AddFieldSectionAsync("Two-Factor Authentication");// Fill in the TOTP code details (form is already visible)+ // The name field is hidden by default and revealed via the optional toggle.+ await Page.Locator("button[id='add-totp-name']").ClickAsync();var nameInput = Page.Locator("input[id='totp-name']");var secretKeyInput = Page.Locator("input[id='totp-secret']");@@ -78,6 +80,8 @@ public class TotpTests : ClientPlaywrightTestawait AddFieldSectionAsync("Two-Factor Authentication");// Fill in the TOTP code details (form is already visible)+ // The name field is hidden by default and revealed via the optional toggle.+ await Page.Locator("button[id='add-totp-name']").ClickAsync();await Page.Locator("input[id='totp-name']").FillAsync("TOTP to Delete");await Page.Locator("input[id='totp-secret']").FillAsync("JBSWY3DPEHPK3PXP");diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.csindex 16e743eb6..40b519a18 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs@@ -211,9 +211,10 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest{// Add TOTP sectionawait AddFieldSectionAsync("Two-Factor Authentication");- await Page.WaitForSelectorAsync("input#totp-name");+ await Page.WaitForSelectorAsync("input#totp-secret");- // Fill TOTP fields+ // Fill TOTP fields (name field is hidden by default, reveal it via the optional toggle)+ await Page.Locator("button[id='add-totp-name']").ClickAsync();await Page.FillAsync("input#totp-name", "Test TOTP");await Page.FillAsync("input#totp-secret", "JBSWY3DPEHPK3PXP");});diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.csindex 40bc6c419..223a2201d 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs@@ -265,7 +265,7 @@ public static class BaseImporteritem.TotpCodes.Add(new TotpCode{Id = Guid.NewGuid(),- Name = name ?? "Authenticator",+ Name = name ?? string.Empty,SecretKey = secretKey,CreatedAt = createdAt,UpdatedAt = updatedAt,