Implement PIN verification
MODIFY
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml
xmlns:lockscreen="clr-namespace:WalletWasabi.Gui.Controls.LockScreen;assembly=WalletWasabi.Gui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ActiveLockScreenType="{Binding ActiveLockScreen}"
- IsLocked="{Binding IsLocked, Mode=TwoWay}">
+ IsLocked="{Binding IsLocked, Mode=TwoWay}"
+ PINHash="{Binding PINHash}">
<ContentControl x:Name="LockScreenHost"/>
</lockscreen:LockScreen>
\ No newline at end of file

MODIFY
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml.cs
@@ -11,6 +11,8 @@ namespace WalletWasabi.Gui.Controls.LockScreen
internal class LockScreen : UserControl
{
private bool _isLocked;
+ private string _pinHash;
+
private LockScreenType _activeLockScreenType;
private ContentControl LockScreenHost;
private LockScreenImpl CurrentLockScreen;
@@ -36,6 +38,16 @@ namespace WalletWasabi.Gui.Controls.LockScreen
set => this.SetAndRaise(IsLockedProperty, ref _isLocked, value);
}
+ public static readonly DirectProperty<LockScreen, string> PINHashProperty =
+ AvaloniaProperty.RegisterDirect<LockScreen, string>(nameof(PINHash),
+ o => o.PINHash,
+ (o, v) => o.PINHash = v);
+ public string PINHash
+ {
+ get => _pinHash;
+ set => this.SetAndRaise(PINHashProperty, ref _pinHash, value);
+ }
+
public LockScreen()
{
InitializeComponent();
@@ -48,24 +60,28 @@ namespace WalletWasabi.Gui.Controls.LockScreen
private void OnActiveLockScreenTypeChanged(LockScreenType obj)
{
+
+ ScreenImplDisposables?.Dispose();
+ ScreenImplDisposables = new CompositeDisposable();
+
switch (obj)
{
- case LockScreenType.SlideLock:
- CurrentLockScreen = new SlideLock();
- break;
case LockScreenType.PINLock:
- CurrentLockScreen = new PINLock();
+ var pinLock = new PINLock();
+ CurrentLockScreen = pinLock;
+
+ this.WhenAnyValue(x => x.PINHash)
+ .Subscribe(y => pinLock.PINHash = y)
+ .DisposeWith(ScreenImplDisposables);
+
break;
default:
- CurrentLockScreen = new SimpleLock();
+ CurrentLockScreen = new SlideLock();
break;
}
LockScreenHost.Content = CurrentLockScreen;
- ScreenImplDisposables?.Dispose();
- ScreenImplDisposables = new CompositeDisposable();
-
this.WhenAnyValue(x => x.IsLocked)
.BindTo(CurrentLockScreen, y => y.IsLocked)
.DisposeWith(ScreenImplDisposables);

MODIFY
WalletWasabi.Gui/Controls/LockScreen/PINLock.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/PINLock.xaml.cs
@@ -8,6 +8,9 @@ using Avalonia.Controls.Primitives;
using ReactiveUI;
using Avalonia;
using Avalonia.Interactivity;
+using System.Reactive.Linq;
+using System.Security.Cryptography;
+using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.Controls.LockScreen
{
@@ -15,20 +18,35 @@ namespace WalletWasabi.Gui.Controls.LockScreen
{
public Grid Shade { get; }
+ private NoparaPasswordBox PinLockPwdBox;
+
+ internal string PINHash { get; set; }
+
public PINLock() : base()
{
InitializeComponent();
- var unlockButton = this.FindControl<Button>("UnlockButton");
this.Shade = this.FindControl<Grid>("Shade");
+ this.PinLockPwdBox = this.FindControl<NoparaPasswordBox>("PinLockPwdBox");
- unlockButton.Click += unlockButton_Clicked;
+ PinLockPwdBox.WhenAnyValue(x => x.Password)
+ .Select(Guard.Correct)
+ .Where(x => x != string.Empty)
+ .DistinctUntilChanged()
+ .Throttle(TimeSpan.FromSeconds(1d))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(CheckPIN);
}
- private void unlockButton_Clicked(object sender, RoutedEventArgs e)
+ private void CheckPIN(string obj)
{
+ var currentHash = HashHelpers.GenerateSha256Hash(obj);
+ if (currentHash == PINHash)
+ {
+ PinLockPwdBox.Password = "";
this.IsLocked = false;
}
+ }
private void InitializeComponent()
{

MODIFY
WalletWasabi.Gui/Models/LockScreenType.cs
WalletWasabi.Gui/Models/LockScreenType.cs
@@ -11,6 +11,5 @@ namespace WalletWasabi.Gui.Models
{
SlideLock,
PINLock,
- Simple,
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Gui/ViewModels/LockScreenViewModel.cs
WalletWasabi.Gui/ViewModels/LockScreenViewModel.cs
@@ -31,6 +31,13 @@ namespace WalletWasabi.Gui.ViewModels
set => this.RaiseAndSetIfChanged(ref _isLocked, value);
}
+ private string _pinHash;
+ public string PINHash
+ {
+ get => _pinHash;
+ set => this.RaiseAndSetIfChanged(ref _pinHash, value);
+ }
+
public void Initialize()
{
Global.UiConfig.WhenAnyValue(x => x.LockScreenActive)
@@ -44,6 +51,10 @@ namespace WalletWasabi.Gui.ViewModels
Global.UiConfig.WhenAnyValue(x => x.LockScreenType)
.BindTo(this, y => y.ActiveLockScreen)
.DisposeWith(Disposables);
+
+ Global.UiConfig.WhenAnyValue(x => x.LockScreenPinHash)
+ .BindTo(this, y => y.PINHash)
+ .DisposeWith(Disposables);
}
}
}
\ No newline at end of file

Implement PIN verification