Skip to content

Commit 30651c4

Browse files
Remove save password functionality
1 parent 1d24f4c commit 30651c4

File tree

8 files changed

+40
-64
lines changed

8 files changed

+40
-64
lines changed

Console/CmdWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public CmdWorker(List<CmdArgument> args) {
1919
case "connection":
2020
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(cmd.Params[0]);
2121
host.Server = sb.DataSource;
22-
host.AuthType = sb.IntegratedSecurity ? AuthTypes.WINDOWS : AuthTypes.SQLSERVER;
22+
host.AuthType = sb.IntegratedSecurity ? AuthTypes.Windows : AuthTypes.Sql;
2323
host.User = sb.UserID;
2424
if (!string.IsNullOrEmpty(sb.InitialCatalog)) {
2525
host.Databases.Add(sb.InitialCatalog);

Forms/ConnectionBox.Designer.cs

Lines changed: 7 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/ConnectionBox.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public Host GetHost() {
2424
AuthType = _authType,
2525
User = _user,
2626
Password = _password,
27-
SavePassword = _savePassword,
2827
Databases = _databases,
2928
IsUserConnection = true,
3029
ServerInfo = _serverInfo
@@ -122,11 +121,6 @@ private string _password {
122121
set => boxPassword.Text = value;
123122
}
124123

125-
private bool _savePassword {
126-
get => boxSavePassword.Checked;
127-
set => boxSavePassword.Checked = value;
128-
}
129-
130124
private List<string> _databases;
131125
private ServerInfo _serverInfo;
132126

@@ -151,28 +145,24 @@ private void BoxServerSelectionChanged(object sender, EventArgs e) {
151145
_authType = host.AuthType;
152146
_user = host.User;
153147
_password = host.Password;
154-
_savePassword = host.SavePassword;
155148
_databases = host.Databases;
156149
}
157150
}
158151

159152
private void BoxAuthTypeSelectionChanged(object sender, EventArgs e) {
160-
bool sqlAuth = (_authType == AuthTypes.SQLSERVER);
153+
bool sqlAuth = (_authType == AuthTypes.Sql);
161154
boxUser.Enabled =
162-
boxPassword.Enabled =
163-
boxSavePassword.Enabled = sqlAuth;
155+
boxPassword.Enabled = sqlAuth;
164156

165157
if (!sqlAuth) {
166158
_user = _password = null;
167-
_savePassword = false;
168159
}
169160
else {
170161
_user = "sa";
171162
}
172163
}
173164

174165
private void UpdateControlUsage(bool enabled) {
175-
176166
foreach(Control c in Controls) {
177167
c.Enabled = enabled;
178168
}
@@ -182,14 +172,13 @@ private void UpdateControlUsage(bool enabled) {
182172

183173
if (enabled) {
184174
boxUser.Enabled =
185-
boxPassword.Enabled =
186-
boxSavePassword.Enabled = (_authType == AuthTypes.SQLSERVER);
175+
boxPassword.Enabled = (_authType == AuthTypes.Sql);
187176
}
188177
}
189178

190179
private void EditValueChanged(object sender, EventArgs e) {
191180
buttonOK.Enabled =
192-
!string.IsNullOrEmpty(_server) && !(string.IsNullOrEmpty(_user) && _authType == AuthTypes.SQLSERVER);
181+
!string.IsNullOrEmpty(_server) && !(string.IsNullOrEmpty(_user) && _authType == AuthTypes.Sql);
193182
}
194183

195184
#endregion

Forms/MainBox.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private void FixIndexesFinish(object sender, RunWorkerCompletedEventArgs e) {
459459
#region Dialogs
460460

461461
private void MainBox_Shown(object sender, EventArgs e) {
462-
ShowConnectionBox();
462+
ShowConnectionManagerBox();
463463
}
464464

465465
private void ShowDatabaseBox(bool isConnectionChanged) {
@@ -483,6 +483,15 @@ private void ShowDatabaseBox(bool isConnectionChanged) {
483483
}
484484
}
485485

486+
private void ShowConnectionManagerBox() {
487+
using (ConnectionBox form = new ConnectionBox()) {
488+
if (form.ShowDialog(this) == DialogResult.OK) {
489+
Host host = form.GetHost();
490+
Host lastHost = Settings.Hosts[0];
491+
}
492+
}
493+
}
494+
486495
private void ShowConnectionBox() {
487496
using (ConnectionBox form = new ConnectionBox()) {
488497
if (form.ShowDialog(this) == DialogResult.OK) {

Server/Connection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private static string GetConnectionString(Host host, string database) {
1313
InitialCatalog = database ?? "master"
1414
};
1515

16-
if (host.AuthType == AuthTypes.WINDOWS) {
16+
if (host.AuthType == AuthTypes.Windows) {
1717
builder.IntegratedSecurity = true;
1818
}
1919
else {

Server/Host.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ namespace SQLIndexManager {
88
public class Host {
99

1010
[XmlAttribute]
11-
public string Server;
11+
public string Server { get; set; }
1212

1313
[XmlAttribute]
14-
public AuthTypes AuthType;
14+
public AuthTypes AuthType { get; set; }
1515

1616
[XmlAttribute]
17-
public string User;
17+
public string User { get; set; }
1818

1919
[XmlAttribute]
20-
public string Password;
20+
public string Password { get; set; }
2121

2222
[XmlElement]
23-
public List<string> Databases;
23+
public List<string> Databases { get; set; }
2424

2525
[XmlIgnore]
26-
public bool IsUserConnection;
26+
public bool IsUserConnection { get; set; }
2727

2828
[XmlIgnore]
29-
public bool SavePassword;
30-
31-
[XmlIgnore]
32-
public ServerInfo ServerInfo;
29+
public ServerInfo ServerInfo { get; set; }
3330

3431
public Host() {
35-
AuthType = AuthTypes.WINDOWS;
32+
AuthType = AuthTypes.Windows;
3633
Databases = new List<string>();
3734
}
3835

Settings/Settings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public static Host ActiveHost {
3131

3232
public static ServerInfo ServerInfo => _activeHost.ServerInfo;
3333

34-
public static List<Host> Hosts => Instance.Hosts;
34+
public static List<Host> Hosts {
35+
get => Instance.Hosts;
36+
set => Instance.Hosts = value;
37+
}
3538

3639
public static Options Options {
3740
get => Instance.Options;
@@ -71,10 +74,8 @@ private static void Save() {
7174
using (FileStream writer = File.OpenWrite(AppInfo.SettingFileName)) {
7275
_current.Hosts.RemoveAll(s => !s.IsUserConnection);
7376
_current.Hosts.ForEach(s => {
74-
if (s.AuthType == AuthTypes.SQLSERVER && s.Password != null) {
75-
s.Password = s.SavePassword
76-
? AES.Encrypt(s.Password)
77-
: null;
77+
if (s.AuthType == AuthTypes.Sql && s.Password != null) {
78+
s.Password = AES.Encrypt(s.Password);
7879
}
7980
});
8081

@@ -98,9 +99,8 @@ private static void Load() {
9899
_current.Hosts.RemoveAll(_ => _.Server == null);
99100
_current.Hosts.ForEach(s => {
100101
s.IsUserConnection = true;
101-
if (s.AuthType == AuthTypes.SQLSERVER && !string.IsNullOrEmpty(s.Password)) {
102+
if (s.AuthType == AuthTypes.Sql && !string.IsNullOrEmpty(s.Password)) {
102103
s.Password = AES.Decrypt(s.Password);
103-
s.SavePassword = true;
104104
}
105105
});
106106

Types/AuthTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace SQLIndexManager {
22

33
public enum AuthTypes {
4-
WINDOWS = 0,
5-
SQLSERVER = 1
4+
Windows = 0,
5+
Sql = 1
66
}
77

88
}

0 commit comments

Comments
 (0)