-
Notifications
You must be signed in to change notification settings - Fork 1
/
PasswordBox.cs
46 lines (40 loc) · 1.44 KB
/
PasswordBox.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
using System;
using System.Windows.Forms;
namespace SynchronizedPasswordChanger
{
/// <summary>
/// I originally wrote this using SecureStrings for the credentials.
/// However, it added complexity, and ultimately didn't seem worth
/// it. If a bad actor has physical access enough to manipulate your
/// process' internal memory, then you're already pwnd.
/// </summary>
public partial class PasswordBox : UserControl
{
public PasswordBox()
{
InitializeComponent();
}
public bool ShowPassword
{
get => !_tbPassword.UseSystemPasswordChar;
set => SetShowPassword(value);
}
public override string Text { get => _tbPassword.Text; set => _tbPassword.Text = value; }
public EventHandler ShowPasswordChanged;
public EventHandler PasswordChanged;
private void OnPasswordChanged(object sender, EventArgs e)
{
PasswordChanged?.Invoke(this, EventArgs.Empty);
}
private void SetShowPassword(bool show)
{
_tbPassword.UseSystemPasswordChar = !show;
_btnShow.Text = show ? "Hide" : "Show";
ShowPasswordChanged?.Invoke(this, EventArgs.Empty);
}
private void OnShowClicked(object sender, EventArgs e)
{
SetShowPassword(_tbPassword.UseSystemPasswordChar);
}
}
}