private void SaveSettings() { Settings.User = User; Settings.Password = EncryptionHelper.EncryptString(SecureStringHelper.SecureStringToString(Password), EncryptionHelper.Base64Decode(Key), 8); if ((URL.StartsWith("http://")) || (URL.StartsWith("https://"))) { Settings.URL = URL; } else { Settings.URL = ""; } Settings.UseDefaultCredentials = UseDefaultCredentials; Settings.IgnoreCertificateErrors = IgnoreCertificateErrors; Settings.AllowRedirection = AllowRedirection; Settings.UseAutodiscover = UseAutodiscover; Settings.Key = Key; Settings.SaveSettings(); }
private void BtnOK_Click(object sender, EventArgs e) { bool checkSucceded = false; formSettings.Key = formSettings.Key; // check if there are user and password set if (!chkUseDefaultCredentials.Checked) { if (txtPassword.Enabled) { if ((txtUser.Text.Length == 0) || (txtPassword.Text.Length == 0)) { MessageBox.Show("Please enter a user name and password", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Error); checkSucceded = false; } else { formSettings.User = txtUser.Text; formSettings.Password = EncryptionHelper.EncryptString(txtPassword.Text, EncryptionHelper.Base64Decode(Key), 8); checkSucceded = true; } } else { checkSucceded = true; } } else { formSettings.UseDefaultCredentials = chkUseDefaultCredentials.Checked; formSettings.User = ""; formSettings.Password = ""; checkSucceded = true; } if (!(chkAutodiscover.Checked)) { if (txtUrl.Text.Length == 0) { MessageBox.Show("Please enter valid URL", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Error); checkSucceded = false; } else if ((txtUrl.Text.StartsWith("https://")) || (txtUrl.Text.StartsWith("http://"))) { formSettings.URL = txtUrl.Text; checkSucceded = true; } else { MessageBox.Show("Please enter valid URL", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Error); checkSucceded = false; } } else { formSettings.UseAutodiscover = chkUseDefaultCredentials.Checked; formSettings.URL = ""; } if (checkSucceded) { formSettings.IgnoreCertificateErrors = chkIgnoreCertificateErrors.Checked; formSettings.AllowRedirection = chkAlloRedirection.Checked; formSettings.UseDefaultCredentials = chkUseDefaultCredentials.Checked; formSettings.UseAutodiscover = chkAutodiscover.Checked; formSettings.SaveSettings(); this.DialogResult = DialogResult.OK; this.Close(); } }