-
Notifications
You must be signed in to change notification settings - Fork 20
/
FormHttpsAuth.cs
65 lines (57 loc) · 2.08 KB
/
FormHttpsAuth.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
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace GitForce
{
public partial class FormHttpsAuth : Form
{
/// <summary>
/// Keep user name and password fields as typed in the control
/// </summary>
public string Username
{
set { textUsername.Text = value.Trim(); }
get { return textUsername.Text.Trim(); }
}
public string Password
{
set { textPassword.Text = value.Trim(); }
get { return textPassword.Text.Trim(); }
}
/// <summary>
/// Form constructor
/// </summary>
public FormHttpsAuth(bool enableUsername)
{
InitializeComponent();
ClassWinGeometry.Restore(this);
textUsername.Enabled = enableUsername;
}
/// <summary>
/// Form is closing
/// </summary>
private void FormHttpsAuth_FormClosing(object sender, FormClosingEventArgs e)
{
ClassWinGeometry.Save(this);
}
/// <summary>
/// Show or hide password field
/// </summary>
private void CheckShowCheckedChanged(object sender, System.EventArgs e)
{
textPassword.UseSystemPasswordChar = !checkReveal.Checked;
}
/// <summary>
/// Enables or disables OK button based on validity of the user name and password fields
/// </summary>
private void ValidateOk(object sender, System.EventArgs e)
{
// Validator for the user name field: must start with a letter and ...
string username = textUsername.Text.Trim();
Regex r = new Regex("^[a-zA-Z][a-zA-Z0-9_]*$");
// This is a really lame validator for the password field
// We simply want to avoid some 'dangerous' characters, including spaces
string password = textPassword.Text.Trim();
btOK.Enabled = (!textUsername.Enabled || r.IsMatch(username)) && (password.Length > 0) && password.IndexOfAny(@" \/".ToCharArray()) == -1;
}
}
}