This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
/
GlobalPassVerify.xaml.cs
121 lines (101 loc) · 3.1 KB
/
GlobalPassVerify.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Navigation;
using KeePass.Analytics;
using KeePass.I18n;
using KeePass.Utils;
using Microsoft.Phone.Shell;
namespace KeePass
{
public partial class GlobalPassVerify
{
private readonly ApplicationBarIconButton _cmdOk;
private readonly BackgroundWorker _wkVerify;
public GlobalPassVerify()
{
InitializeComponent();
_cmdOk = this.AppButton(0);
_cmdOk.Text = Strings.GlobalPassVerify_OK;
this.AppButton(1).Text = Strings.Clear;
_wkVerify = new BackgroundWorker();
_wkVerify.DoWork += _wkVerify_DoWork;
_wkVerify.RunWorkerCompleted +=
_wkVerify_RunWorkerCompleted;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
AnalyticsTracker.Track("global_pass");
}
private void Verify()
{
txtPass.IsEnabled = false;
ApplicationBar.IsVisible = false;
_wkVerify.RunWorkerAsync(
txtPass.Password);
}
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
this.ClearBackStack();
}
private static void _wkVerify_DoWork(
object sender, DoWorkEventArgs e)
{
var password = (string)e.Argument;
var globalPass = GlobalPassHandler.Instance;
if (globalPass.Verify(password))
{
e.Result = true;
return;
}
e.Result = false;
Thread.Sleep(1000);
}
private void _wkVerify_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs e)
{
var correct = (bool)e.Result;
if (correct)
{
NavigationService.GoBack();
return;
}
txtPass.IsEnabled = true;
ApplicationBar.IsVisible = true;
txtPass.Focus();
txtPass.SelectAll();
}
private void cmdClear_Click(
object sender, EventArgs e)
{
txtPass.Password = string.Empty;
txtPass.Focus();
}
private void cmdOK_Click(
object sender, EventArgs e)
{
Verify();
}
private void txtPass_KeyDown(
object sender, KeyEventArgs e)
{
if (e.IsEnter() && _cmdOk.IsEnabled)
Verify();
}
private void txtPass_Loaded(
object sender, RoutedEventArgs e)
{
txtPass.Focus();
}
private void txtPass_PasswordChanged(
object sender, RoutedEventArgs e)
{
_cmdOk.IsEnabled = !string
.IsNullOrEmpty(txtPass.Password);
}
}
}