-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordPracticeForm.cs
103 lines (86 loc) · 3.04 KB
/
PasswordPracticeForm.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
using System;
using System.Drawing;
using System.Media;
using System.Windows.Forms;
using KeePass.App;
using KeePass.UI;
using KeePassLib.Security;
namespace KeePassPasswordPractice
{
public partial class PasswordPracticeForm : Form
{
public PasswordPracticeForm(ProtectedString password)
{
this.InitializeComponent();
this._Password = password;
this.PeekTextBox.UseSystemPasswordChar = false;
this.PeekTextBox.TextEx = password;
this.PeekTextBox.Select(password.Length, 0);
this.Icon = AppIcons.Default;
BannerFactory.CreateBannerEx(this, this.BannerImage, Properties.Resources.icon_48x48, "Password Practice", "Practice the password of the entry.");
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.F1)
{
this.PeekButton.Checked ^= true;
this.PeekTextBox.Focus();
this.PasswordTextBox.Focus();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void PasswordTextBox_TextChanged(object sender, EventArgs e)
{
this.PasswordTextBox.BackColor = this.CorrectPassword ? _GreenBack : SystemColors.Window;
}
private void PasswordTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
this.PasswordAsteriskButton.Checked ^= true;
}
}
private void PasswordAsteriskButton_CheckedChanged(object sender, EventArgs e)
{
this.PasswordTextBox.UseSystemPasswordChar = this.PasswordAsteriskButton.Checked;
var selectionStart = this.PasswordTextBox.SelectionStart;
var selectionLength = this.PasswordTextBox.SelectionLength;
this.PasswordTextBox.TextEx = this.PasswordTextBox.TextEx;
this.PasswordTextBox.Select(selectionStart, selectionLength);
}
private void PeekButton_CheckedChanged(object sender, EventArgs e)
{
this.PeekPanel.Visible = this.PeekButton.Checked;
this.PasswordPanel.Visible = !this.PeekButton.Checked;
}
private void OkButton_Click(object sender, EventArgs e)
{
if (!this.CorrectPassword)
{
SystemSounds.Exclamation.Play();
}
else
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
public ProtectedString EnteredPassword
{
get
{
return this.PasswordTextBox.TextEx;
}
}
public bool CorrectPassword
{
get
{
return this.EnteredPassword.Equals(this._Password, false);
}
}
private readonly ProtectedString _Password;
private static readonly Color _GreenBack = Color.FromArgb(192, 255, 192);
}
}