-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSecureInputBoxDialog.cs
More file actions
199 lines (180 loc) · 7.59 KB
/
SecureInputBoxDialog.cs
File metadata and controls
199 lines (180 loc) · 7.59 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
RMLibUI: Visual support classes/components used by multiple R&M Software programs
Copyright (C) 2008-2014 Rick Parrish, R&M Software
This file is part of RMLibUI.
RMLibUI is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
RMLibUI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RMLibUI. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Windows.Forms;
using RandM.RMLib;
namespace RandM.RMLibUI
{
public class frmRMSecureInputBox : Form
{
#region Windows Contols and Constructor
private System.Windows.Forms.Label lblPrompt;
private System.Windows.Forms.Button cmdOK;
private RandM.RMLibUI.SecureTextBox txtInput;
private CheckBox chkShowPassword;
/// <summary>
/// Required designer variable.
///</summary>
private System.ComponentModel.Container components = null;
#endregion
#region Dispose
/// <summary>
/// Clean up any resources being used.
///</summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
_SecureText.Dispose();
}
}
base.Dispose(disposing);
}
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///</summary>
private void InitializeComponent()
{
this.lblPrompt = new System.Windows.Forms.Label();
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
this.txtInput = new RandM.RMLibUI.SecureTextBox();
this.chkShowPassword = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// lblPrompt
//
this.lblPrompt.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblPrompt.BackColor = System.Drawing.SystemColors.Control;
this.lblPrompt.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPrompt.Location = new System.Drawing.Point(12, 9);
this.lblPrompt.Name = "lblPrompt";
this.lblPrompt.Size = new System.Drawing.Size(295, 111);
this.lblPrompt.TabIndex = 99;
//
// cmdOK
//
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(312, 5);
this.cmdOK.Name = "cmdOK";
this.cmdOK.Size = new System.Drawing.Size(75, 25);
this.cmdOK.TabIndex = 1;
this.cmdOK.Text = "&OK";
this.cmdOK.UseVisualStyleBackColor = true;
this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
//
// cmdCancel
//
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(312, 36);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.Size = new System.Drawing.Size(75, 25);
this.cmdCancel.TabIndex = 2;
this.cmdCancel.Text = "&Cancel";
this.cmdCancel.UseVisualStyleBackColor = true;
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(8, 95);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(379, 20);
this.txtInput.TabIndex = 0;
this.txtInput.UseSystemPasswordChar = true;
//
// chkShowPassword
//
this.chkShowPassword.AutoSize = true;
this.chkShowPassword.Location = new System.Drawing.Point(8, 121);
this.chkShowPassword.Name = "chkShowPassword";
this.chkShowPassword.Size = new System.Drawing.Size(101, 17);
this.chkShowPassword.TabIndex = 100;
this.chkShowPassword.Text = "Show password";
this.chkShowPassword.UseVisualStyleBackColor = true;
this.chkShowPassword.CheckedChanged += new System.EventHandler(this.chkShowPassword_CheckedChanged);
//
// frmRMSecureInputBox
//
this.AcceptButton = this.cmdOK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(394, 157);
this.Controls.Add(this.chkShowPassword);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.cmdCancel);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.lblPrompt);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmRMSecureInputBox";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "R&M Secure Input Box";
this.Load += new System.EventHandler(this.frmRMSecureInputBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button cmdCancel;
#endregion
public frmRMSecureInputBox(string prompt, string caption)
{
InitializeComponent();
// Initialize dialog
lblPrompt.Text = prompt;
this.Text = caption;
// Set default return value
_SecureText.Clear();
}
private void cmdOK_Click(object sender, EventArgs e)
{
// Save new return value (we call GetSecureText() to get the value, and not the actual instance of the RMSecureString)
_SecureText = txtInput.SecureText.GetSecureText();
}
private void frmRMSecureInputBox_Load(object sender, System.EventArgs e)
{
// Focus text box with all text highlighted
txtInput.SelectAll();
txtInput.Focus();
}
public RMSecureString SecureText
{
get { return _SecureText; }
}
private RMSecureString _SecureText = new RMSecureString();
private void chkShowPassword_CheckedChanged(object sender, EventArgs e)
{
if (chkShowPassword.Checked)
{
txtInput.PasswordChar = '\0';
txtInput.UseSystemPasswordChar = false;
}
else
{
txtInput.PasswordChar = '*';
txtInput.UseSystemPasswordChar = true;
}
}
}
}