Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update change password form validation UI (#773)
Leendert de Borst53cb7c4961ac
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/Security/ChangePassword.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/Security/ChangePassword.razorindex 636b7f37b..be2f42eac 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/Security/ChangePassword.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/Security/ChangePassword.razor@@ -8,6 +8,7 @@@using AliasVault.Client.Main.Components.Shared@using AliasVault.Client.Main.Constants@using Microsoft.Extensions.Localization+@using System.Timers@inherits MainBase@inject HttpClient Http@inject RustCoreService RustCoreService@@ -42,7 +43,7 @@ else<div><label for="newPassword" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@Localizer["NewPasswordLabel"]</label>- <input type="password" id="newPassword" @bind="PasswordChangeFormModel.NewPassword" @oninput="OnPasswordInput"+ <input type="password" id="newPassword" @bind="PasswordChangeFormModel.NewPassword" @oninput="OnPasswordInput" @onfocus="OnPasswordFocus"class="bg-gray-50 border border-gray-300 text-gray-900 sm: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:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"required /><PasswordStrengthIndicator @ref="PasswordStrengthIndicatorRef" Password="@PasswordChangeFormModel.NewPassword" />@@ -50,15 +51,15 @@ else<div><label for="newPasswordConfirm" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@Localizer["ConfirmNewPasswordLabel"]</label>- <input type="password" id="newPasswordConfirm" @bind="PasswordChangeFormModel.NewPasswordConfirm" @oninput="OnConfirmPasswordInput"+ <input type="password" id="newPasswordConfirm" @bind="PasswordChangeFormModel.NewPasswordConfirm" @oninput="OnConfirmPasswordInput" @onfocus="OnPasswordFocus"class="bg-gray-50 border border-gray-300 text-gray-900 sm: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:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"required /></div>- @if (!string.IsNullOrEmpty(PasswordStrengthError))+ @if (!string.IsNullOrEmpty(PasswordValidationError)){- <div class="p-3 text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20 rounded-lg">- @PasswordStrengthError+ <div class="mt-2 text-sm text-red-600 dark:text-red-400">+ @PasswordValidationError</div>}@@ -121,9 +122,14 @@ elseprivate PasswordStrengthIndicator? PasswordStrengthIndicatorRef { get; set; }/// <summary>- /// Error message for password strength validation.+ /// Error message for password validation./// </summary>- private string PasswordStrengthError { get; set; } = string.Empty;+ private string PasswordValidationError { get; set; } = string.Empty;++ /// <summary>+ /// Timer for debouncing password validation.+ /// </summary>+ private Timer? _passwordDebounceTimer;/// <summary>/// Gets a value indicating whether the submit button should be enabled.@@ -133,6 +139,7 @@ else!string.IsNullOrWhiteSpace(PasswordChangeFormModel.NewPassword) &&!string.IsNullOrWhiteSpace(PasswordChangeFormModel.NewPasswordConfirm) &&PasswordChangeFormModel.NewPassword == PasswordChangeFormModel.NewPasswordConfirm &&+ string.IsNullOrEmpty(PasswordValidationError) &&PasswordStrengthIndicatorRef != null &&PasswordStrengthIndicatorRef.MeetsMinimumRequirement();@@ -142,8 +149,7 @@ elseprivate void OnPasswordInput(ChangeEventArgs e){PasswordChangeFormModel.NewPassword = e.Value?.ToString() ?? string.Empty;- PasswordStrengthError = string.Empty;- StateHasChanged();+ ValidatePasswordWithDebounce();}/// <summary>@@ -152,7 +158,65 @@ elseprivate void OnConfirmPasswordInput(ChangeEventArgs e){PasswordChangeFormModel.NewPasswordConfirm = e.Value?.ToString() ?? string.Empty;+ ValidatePasswordImmediate();+ }++ /// <summary>+ /// Handles password field focus to clear error messages.+ /// </summary>+ private void OnPasswordFocus(FocusEventArgs e)+ {+ PasswordValidationError = string.Empty;+ StateHasChanged();+ }++ /// <summary>+ /// Validates the password with debounce.+ /// </summary>+ private void ValidatePasswordWithDebounce()+ {+ PasswordValidationError = string.Empty;StateHasChanged();++ _passwordDebounceTimer?.Stop();+ _passwordDebounceTimer?.Start();+ }++ /// <summary>+ /// Validates the password immediately (for confirm password field).+ /// </summary>+ private async void ValidatePasswordImmediate()+ {+ await ValidatePasswordDebounced();+ }++ /// <summary>+ /// Validates the password after input has stopped.+ /// </summary>+ private async Task ValidatePasswordDebounced()+ {+ await InvokeAsync(() =>+ {+ var minLength = PasswordStrengthConstants.MinimumGoodPasswordLength;+ if (!string.IsNullOrWhiteSpace(PasswordChangeFormModel.NewPassword) &&+ PasswordChangeFormModel.NewPassword.Length < minLength)+ {+ PasswordValidationError = Localizer["PasswordStrengthTooWeakError", minLength];+ StateHasChanged();+ return;+ }++ if (!string.IsNullOrWhiteSpace(PasswordChangeFormModel.NewPasswordConfirm) &&+ PasswordChangeFormModel.NewPassword != PasswordChangeFormModel.NewPasswordConfirm)+ {+ PasswordValidationError = Localizer["PasswordsMismatchError"];+ StateHasChanged();+ return;+ }++ PasswordValidationError = string.Empty;+ StateHasChanged();+ });}/// <inheritdoc />@@ -162,6 +226,22 @@ elseBreadcrumbItems.Add(new BreadcrumbItem { DisplayName = Localizer["BreadcrumbSecuritySettings"], Url = "/settings/security" });BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = Localizer["BreadcrumbChangePassword"] });++ // Initialize debounce timer+ _passwordDebounceTimer = new Timer(800);+ _passwordDebounceTimer.Elapsed += async (sender, e) => await ValidatePasswordDebounced();+ _passwordDebounceTimer.AutoReset = false;+ }++ /// <inheritdoc />+ protected override void Dispose(bool disposing)+ {+ if (disposing)+ {+ _passwordDebounceTimer?.Dispose();+ }++ base.Dispose(disposing);}/// <inheritdoc />@@ -209,12 +289,21 @@ elseprivate async Task InitiatePasswordChange(){// Clear any previous errors- PasswordStrengthError = string.Empty;+ PasswordValidationError = string.Empty;++ // Validate password before proceeding+ var minLength = PasswordStrengthConstants.MinimumGoodPasswordLength;+ if (PasswordChangeFormModel.NewPassword.Length < minLength)+ {+ PasswordValidationError = Localizer["PasswordStrengthTooWeakError", minLength];+ StateHasChanged();+ return;+ }// Validate password strength before proceedingif (PasswordStrengthIndicatorRef == null || !PasswordStrengthIndicatorRef.MeetsMinimumRequirement()){- PasswordStrengthError = Localizer["PasswordStrengthTooWeakError", PasswordStrengthConstants.MinimumGoodPasswordLength];+ PasswordValidationError = Localizer["PasswordStrengthTooWeakError", PasswordStrengthConstants.MinimumGoodPasswordLength];StateHasChanged();return;}diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Pages/Settings/Security/ChangePassword.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Pages/Settings/Security/ChangePassword.en.resxindex 316f94e55..6ed0bb14d 100644--- a/apps/server/AliasVault.Client/Resources/Components/Main/Pages/Settings/Security/ChangePassword.en.resx+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Pages/Settings/Security/ChangePassword.en.resx@@ -120,4 +120,8 @@<value>Your new password must be at least {0} characters long.</value><comment>Error message when password strength is too weak. {0} is the minimum password length.</comment></data>+ <data name="PasswordsMismatchError" xml:space="preserve">+ <value>Passwords do not match.</value>+ <comment>Error message when new password and confirmation password don't match</comment>+ </data></root>\ No newline at end of file