prohibit paste of too long password
MODIFY
WalletWasabi.Gui/Controls/NoparaPasswordBox.cs
WalletWasabi.Gui/Controls/NoparaPasswordBox.cs
@@ -75,6 +75,15 @@ namespace WalletWasabi.Gui.Controls
set => SetValue(IsPasswordVisibleProperty, value);
}
+ public static readonly StyledProperty<string> WarningMessageProperty =
+ AvaloniaProperty.Register<NoparaPasswordBox, string>(nameof(WarningMessage), defaultBindingMode: BindingMode.TwoWay);
+
+ public string WarningMessage
+ {
+ get => GetValue(WarningMessageProperty);
+ set => SetValue(WarningMessageProperty, value);
+ }
+
protected override bool IsCopyEnabled => false;
public NoparaPasswordBox()
@@ -231,7 +240,11 @@ namespace WalletWasabi.Gui.Controls
string text = await Application.Current.Clipboard.GetTextAsync();
if (!string.IsNullOrEmpty(text))
{
- e.Handled = OnTextInput(text);
+ e.Handled = OnTextInput(text, true);
+ if (!e.Handled)
+ {
+ DisplayWarning("Password too long (Max 150 characters)");
+ }
}
}
else if (e.Key == Key.Back && Sb.Length > 0) // Backspace button -> delete from the end.
@@ -283,10 +296,10 @@ namespace WalletWasabi.Gui.Controls
protected override void OnTextInput(TextInputEventArgs e)
{
- e.Handled = OnTextInput(e.Text);
+ e.Handled = OnTextInput(e.Text, false);
}
- private bool OnTextInput(string text)
+ private bool OnTextInput(string text, bool isPaste)
{
if (_supressChanges)
{
@@ -301,7 +314,11 @@ namespace WalletWasabi.Gui.Controls
SelectionStart = SelectionEnd = CaretIndex = 0;
_supressChanges = false;
}
- if (CaretIndex == 0)
+ if (isPaste && Sb.Length + text.Length > Constants.MaxPasswordLength) // Don't allow pastes that would be too long
+ {
+ handledCorrectly = false;
+ }
+ else if (CaretIndex == 0)
{
Sb.Insert(0, text);
}
@@ -310,7 +327,7 @@ namespace WalletWasabi.Gui.Controls
Sb.Append(text);
}
- if (Sb.Length > Constants.MaxPasswordLength) // Ensure the maximum length.
+ if (handledCorrectly && Sb.Length > Constants.MaxPasswordLength) // Ensure the maximum length.
{
Sb.Remove(Constants.MaxPasswordLength, Sb.Length - Constants.MaxPasswordLength);
handledCorrectly = false; // Should play beep sound not working on windows.
@@ -350,6 +367,13 @@ namespace WalletWasabi.Gui.Controls
}
}
+ private async void DisplayWarning(string message)
+ {
+ WarningMessage = message;
+ await Task.Delay(2000); // 2 seconds
+ WarningMessage = "";
+ }
+
private void PaintText()
{
if (string.IsNullOrEmpty(_displayText))

MODIFY
WalletWasabi.Gui/Controls/NoparaPasswordBox.xaml
WalletWasabi.Gui/Controls/NoparaPasswordBox.xaml
<Panel>
<TextBlock Name="watermark"
Opacity="0.5"
- Text="{TemplateBinding Watermark}"
- IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}" />
+ Text="{TemplateBinding Watermark}">
+ <TextBlock.IsVisible>
+ <MultiBinding Converter="{x:Static BoolConverters.And}">
+ <Binding RelativeSource="{RelativeSource TemplatedParent}"
+ Path = "WarningMessage"
+ Converter = "{x:Static StringConverters.IsNullOrEmpty}" />
+ <Binding RelativeSource="{RelativeSource TemplatedParent}"
+ Path="Text"
+ Converter="{x:Static StringConverters.IsNullOrEmpty}" />
+ </MultiBinding>
+ </TextBlock.IsVisible>
+ </TextBlock>
<TextPresenter Name="PART_TextPresenter"
Text="{TemplateBinding Text, Mode=TwoWay}"
CaretIndex="{TemplateBinding CaretIndex}"
SelectionEnd="{TemplateBinding SelectionEnd}"
TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="{TemplateBinding TextWrapping}"
- PasswordChar="{TemplateBinding PasswordChar}" />
+ PasswordChar="{TemplateBinding PasswordChar}"
+ IsVisible="{TemplateBinding WarningMessage, Converter={x:Static StringConverters.IsNullOrEmpty}}" />
+ <TextBlock Name="warningMessage"
+ Classes="warningMessage"
+ Text="{TemplateBinding WarningMessage}"
+ IsVisible="{TemplateBinding WarningMessage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
</Panel>
</ScrollViewer>
</DataValidationErrors>

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletView.xaml
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletView.xaml
<TextBlock Text="You cannot recover your wallet without your password. Therefore we strongly advise you to use a password that you will not forget." TextWrapping="Wrap" />
</StackPanel>
<controls:ExtendedTextBox Text="{Binding WalletName}" Watermark="Wallet Name" UseFloatingWatermark="True" />
- <controls:NoparaPasswordBox Password="{Binding Password}" Watermark="Choose a password" UseFloatingWatermark="True" />
+ <controls:NoparaPasswordBox Password="{Binding Password}" Watermark="Choose a password (Max 150 characters)" UseFloatingWatermark="True" />
</StackPanel>
</Grid>
</controls:GroupBox>

prohibit paste of too long password