Add validation methods
MODIFY
WalletWasabi.Gui/Controls/TogglePasswordBox.cs
WalletWasabi.Gui/Controls/TogglePasswordBox.cs
@@ -52,7 +52,6 @@ namespace WalletWasabi.Gui.Controls
maskedButton.WhenAnyValue(x => x.IsPressed)
.Where(x => x)
.ObserveOn(RxApp.MainThreadScheduler)
-
.Subscribe(_ =>
{
IsPasswordVisible = !IsPasswordVisible;

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -11,6 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Gui.ViewModels.Validation;
using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
@@ -342,6 +343,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Global.ChaumianClient.DeactivateFrequentStatusProcessingIfNotMixing();
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -963,6 +963,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _allSelectedAmount, value);
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletInfoViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletInfoViewModel.cs
@@ -7,6 +7,7 @@ using System.Reactive;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.Gui.ViewModels.Validation;
using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Services;
@@ -108,6 +109,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _showSensitiveKeys, value);
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Reactive;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Gui.ViewModels.Validation;
using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
@@ -87,6 +88,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
return isValid && !isReserved;
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -22,6 +22,7 @@ using WalletWasabi.Gui.Controls.WalletExplorer;
using WalletWasabi.Gui.Dialogs;
using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Gui.ViewModels.Validation;
using WalletWasabi.Helpers;
using WalletWasabi.Hwi;
using WalletWasabi.Hwi.Models;
@@ -188,6 +189,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
set => this.RaiseAndSetIfChanged(ref _wallets, value);
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
@@ -9,6 +9,7 @@ using System.IO;
using System.Linq;
using System.Reactive;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Gui.ViewModels.Validation;
using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
@@ -109,6 +110,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
_suggestions = new ObservableCollection<SuggestionViewModel>();
}
+ public string ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ [ValidateMethod(nameof(ValidatePassword))]
public string Password
{
get => _password;

MODIFY
WalletWasabi/Helpers/PasswordHelper.cs
WalletWasabi/Helpers/PasswordHelper.cs
@@ -16,6 +16,7 @@ namespace WalletWasabi.Helpers
public const string CompatibilityPasswordWarnMessage = "Compatibility password was used! Please consider generating a new wallet to ensure recoverability!";
public static readonly string PasswordTooLongMessage = $"Password is too long (Max {MaxPasswordLength} characters).";
public const string TrimmedMessage = "Leading and trailing white spaces were removed!";
+ public const string TrimWarnMessage = "Leading and trailing white spaces will be removed!";
public static string[] GetPossiblePasswords(string originalPassword)
{
@@ -140,5 +141,21 @@ namespace WalletWasabi.Helpers
throw resultException; // Throw the last exception - Invalid password.
}
+
+ public static string ValidatePassword(string password)
+ {
+ List<string> messages = new List<string>();
+ if (IsTrimable(password, out _))
+ {
+ messages.Add(TrimWarnMessage);
+ }
+
+ if (IsTooLong(password, out _))
+ {
+ messages.Add(PasswordTooLongMessage);
+ }
+
+ return string.Join(' ', messages);
+ }
}
}

Add validation methods