Skip to content

Commit ea51f23

Browse files
committed
On validation, if successful will honor the "remember" checkbox. It will clear the various fields if unchecked and erase the fields. If login attempt unsuccessful, no changes will occur to the remember behaviour, if program is relaunched prior to a successful login attempt.
1 parent 10ea19e commit ea51f23

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

Panels/ClientLogin.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ private void ValidateLogin(object sender, EventArgs e)
9595
string username = textBox_username.Text;
9696
string password = textBox_password.Text;
9797
string realm = comboBox_realm.SelectedValue as string;
98-
string otp = textBox_otp.Text;
98+
string otp = checkBox_otp.Checked ? textBox_otp.Text : null;
9999

100100
panel_credentials.Enabled = false;
101101
panel_server.Enabled = false;
102102
Program._Api = new ApiClient(server, port, validateSsl);
103103

104-
if (!checkBox_otp.Checked) { otp = null; }
105-
106104
if (Program._Api.LoginRequest(username, password, realm, otp))
107105
{
108106
SaveCredentials();
@@ -123,32 +121,58 @@ private void ValidateLogin(object sender, EventArgs e)
123121

124122
private void SaveCredentials()
125123
{
124+
bool remember = checkBox_remember.Checked;
125+
126126
Program._Config.SetSetting("Login_Server", textBox_server.Text);
127127
Program._Config.SetSetting("Login_Port", textBox_port.Text);
128128
Program._Config.SetSetting("Login_CheckSSL", checkBox_ssl.Checked);
129-
Program._Config.SetSetting("Login_Username", textBox_username.Text);
130-
Program._Config.SetSetting("Login_Password", textBox_password.Text);
131-
Program._Config.SetSetting("Login_Realm", comboBox_realm.SelectedValue);
132-
Program._Config.SetSetting("Login_OTP", checkBox_otp.Checked);
133-
Program._Config.SetSetting("Login_Remember", checkBox_remember.Checked);
129+
130+
if (remember)
131+
{
132+
Program._Config.SetSetting("Login_Username", textBox_username.Text);
133+
Program._Config.SetSetting("Login_Password", textBox_password.Text);
134+
Program._Config.SetSetting("Login_Realm", comboBox_realm.SelectedValue);
135+
Program._Config.SetSetting("Login_OTP", checkBox_otp.Checked);
136+
}
137+
else
138+
{
139+
Program._Config.SetSetting("Login_Username", "");
140+
Program._Config.SetSetting("Login_Password", "");
141+
Program._Config.SetSetting("Login_Realm", "pam");
142+
Program._Config.SetSetting("Login_OTP", false);
143+
}
144+
145+
Program._Config.SetSetting("Login_Remember", remember);
134146
}
135147

136-
private void LoadCredentials()
148+
public void LoadCredentials()
137149
{
138-
if (Program._Config.GetSetting("Login_Remember") == null) return;
150+
bool remember = (bool)Program._Config.GetSetting("Login_Remember");
139151

140152
textBox_server.Text = (string)Program._Config.GetSetting("Login_Server");
141153
textBox_port.Text = (string)Program._Config.GetSetting("Login_Port");
142154
checkBox_ssl.Checked = (bool)Program._Config.GetSetting("Login_CheckSSL");
155+
143156
ClickCheckServer();
144-
textBox_username.Text = (string)Program._Config.GetSetting("Login_Username");
145-
textBox_password.Text = (string)Program._Config.GetSetting("Login_Password");
146-
checkBox_otp.Checked = (bool)Program._Config.GetSetting("Login_OTP");
147-
checkBox_remember.Checked = (bool)Program._Config.GetSetting("Login_Remember");
148-
if ((bool)Program._Config.GetSetting("Login_OTP")) { textBox_otp.Visible = true; } else { textBox_otp.Visible = false; }
149-
157+
158+
if (remember)
159+
{
160+
textBox_username.Text = (string)Program._Config.GetSetting("Login_Username");
161+
textBox_password.Text = (string)Program._Config.GetSetting("Login_Password");
162+
checkBox_otp.Checked = (bool)Program._Config.GetSetting("Login_OTP");
163+
}
164+
else
165+
{
166+
textBox_username.Text = "";
167+
textBox_password.Text = "";
168+
checkBox_otp.Checked = false;
169+
}
170+
171+
checkBox_remember.Checked = remember;
172+
textBox_otp.Visible = checkBox_otp.Checked;
150173
}
151174

175+
152176
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
153177
{
154178
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))

Panels/MainPanel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ protected override void OnFormClosing(FormClosingEventArgs e)
311311
notifyIcon.Dispose();
312312
var theWindow = (ClientLogin)Program._Panels["ClientLogin"];
313313
theWindow.Show();
314+
theWindow.LoadCredentials();
314315
base.OnFormClosing(e);
315316
}
316317

0 commit comments

Comments
 (0)