Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX Clipboard handling fixes #2100

Merged
merged 33 commits into from
Aug 16, 2019
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
066f42a
Change the logic, add more warning.
molnard Aug 9, 2019
27450ea
Tool to reproduce the cut password and tests.
molnard Aug 9, 2019
7d852d9
Clean up the Enter logic of Passwordbox
molnard Aug 9, 2019
5c37303
Add Avalonia directly so shell will use that
molnard Aug 12, 2019
b5ff074
Add pw compatibility.
molnard Aug 12, 2019
d0f8fb3
Better logic.
molnard Aug 12, 2019
ce02e0a
Add Avalonia.Native
molnard Aug 12, 2019
6398f0a
Add UI warn messages.
molnard Aug 12, 2019
7fcfacf
Fix display error of warn messages
molnard Aug 12, 2019
d8acef9
Code clean.
molnard Aug 12, 2019
0f31d07
Add PasswordTests to CI
molnard Aug 13, 2019
fc7c6ae
Remove unrequired Ref to Avalonia
molnard Aug 13, 2019
6ff65c6
Code clean.
molnard Aug 13, 2019
69d2475
Encoding.Default go home.
molnard Aug 13, 2019
b355f11
Update WalletWasabi/Helpers/Constants.cs
molnard Aug 13, 2019
ad2fe89
Add Avalonia Clipboard tests
molnard Aug 13, 2019
d74a560
Try to fix CI
molnard Aug 13, 2019
cb60045
Removed AvaloniaTests - cannot make it work.
molnard Aug 13, 2019
197cf83
Add OS selectivity
molnard Aug 14, 2019
d7fde2d
Code refactor - pw separation
molnard Aug 15, 2019
fe1dba6
Add functions to Daemon
molnard Aug 15, 2019
5a663a4
Merge branch 'master' into macpwfix
molnard Aug 15, 2019
3664f21
Remove Avalonia.Native
molnard Aug 15, 2019
10472f8
Overfee want overwritten fix
molnard Aug 16, 2019
8a26e10
Add readonly.
molnard Aug 16, 2019
6a758ee
Grammar.
molnard Aug 16, 2019
9258494
Add test.
molnard Aug 16, 2019
83e3d7f
Merge branch 'master' into macpwfix
molnard Aug 16, 2019
3e1d558
Remove GUI from tests.
molnard Aug 16, 2019
d79f64b
Guard when generating wallet.
molnard Aug 16, 2019
53d33cf
Add tests.
molnard Aug 16, 2019
392615a
Use PasswordHelper.IsTooLong.
molnard Aug 16, 2019
ca5099b
Refactor Enter on pwbox.
molnard Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions WalletWasabi.Gui/Controls/NoparaPasswordBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public NoparaPasswordBox()
IsPasswordVisible = x;
});

this.WhenAnyValue(x => x.IsPasswordVisible).Subscribe(IsVisible =>
this.WhenAnyValue(x => x.IsPasswordVisible).Subscribe(_ =>
{
PaintText();
});
Expand Down Expand Up @@ -239,10 +239,6 @@ protected override async void OnKeyDown(KeyEventArgs e)
if (!string.IsNullOrEmpty(text))
{
e.Handled = OnTextInput(text, true);
if (!e.Handled)
{
_ = DisplayWarningAsync("Password too long (Max 150 characters)");
}
}
}
else if (Sb.Length > 0)
Expand Down Expand Up @@ -297,9 +293,17 @@ protected override async void OnKeyDown(KeyEventArgs e)

protected override void OnTextInput(TextInputEventArgs e)
{
e.Handled = OnTextInput(e.Text, false);
var isPaste = e.Text != null && e.Text.Length > 1; // if the ExtendedTextBox right click/Paste is used, OnTextInput will be called directly

e.Handled = OnTextInput(e.Text, isPaste);
}

/// <summary>
/// All text input operation (keydown/paste/delete) should call this.
/// </summary>
/// <param name="text"></param>
/// <param name="isPaste"></param>
/// <returns></returns>
private bool OnTextInput(string text, bool isPaste)
{
if (_supressChanges)
Expand All @@ -315,9 +319,10 @@ private bool OnTextInput(string text, bool isPaste)
SelectionStart = SelectionEnd = CaretIndex = 0;
_supressChanges = false;
}
if (isPaste && Sb.Length + text.Length > Constants.MaxPasswordLength) // Do not allow pastes that would be too long
if (Sb.Length + text.Length > Constants.MaxPasswordLength) // Do not allow insert that would be too long.
{
handledCorrectly = false;
_ = DisplayWarningAsync("Password too long (Max 150 characters)");
molnard marked this conversation as resolved.
Show resolved Hide resolved
}
else if (CaretIndex == 0)
{
Expand All @@ -328,11 +333,13 @@ private bool OnTextInput(string text, bool isPaste)
Sb.Append(text);
}

if (handledCorrectly && Sb.Length > Constants.MaxPasswordLength) // Ensure the maximum length.
if (handledCorrectly && Sb.Length > Constants.MaxPasswordLength) // We should not get here, ensure the maximum length.
{
Sb.Remove(Constants.MaxPasswordLength, Sb.Length - Constants.MaxPasswordLength);
handledCorrectly = false; // Should play beep sound not working on windows.
_ = DisplayWarningAsync("Password too long (Max 150 characters)");
molnard marked this conversation as resolved.
Show resolved Hide resolved
}

PaintText();
return handledCorrectly;
}
Expand Down Expand Up @@ -381,8 +388,26 @@ private void PaintText()
{
GenerateNewRandomSequence();
}
var password = Sb.ToString();

var beforeTrim = password.Length;

password = password.Trim();

var whiteSpacesRemoved = beforeTrim != password.Length;
if (whiteSpacesRemoved)
{
Sb.Clear();
Sb.Append(password);
}

if (whiteSpacesRemoved)
molnard marked this conversation as resolved.
Show resolved Hide resolved
{
_ = DisplayWarningAsync("Leading and trailing are removed!");
molnard marked this conversation as resolved.
Show resolved Hide resolved
}

Password = password;

Password = Sb.ToString();
Text = _displayText.Substring(0, Sb.Length);
if (IsPasswordVisible)
{
Expand Down