[go: up one dir, main page]

Menu

[r1]: / PassManage.cs  Maximize  Restore  History

Download this file

193 lines (171 with data), 6.3 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace RDPManager
{
public partial class PassManage : Form
{
private Dictionary<String, Credentials> users = null; // = new Dictionary<String, Credentials>();
public Dictionary<String, Credentials> Users
{
get { return users; }
set { users = value; }
}
public PassManage()
{
InitializeComponent();
}
private void RefreshLB()
{
int len = 0;
if (lbIDs.Items.Count > 0)
{
lbIDs.Items.Clear();
}
if( users != null )
{
foreach (String SvrName in users.Keys)
{
String spaces = "\t";
len = 3 - SvrName.Length/8;
for (int i = 0; i < len; i++)
{
spaces = spaces + "\t";
}
if (users[SvrName].Domain != "")
{
lbIDs.Items.Add(String.Format("{0}{1}{2}\\{3}", SvrName, spaces, users[SvrName].Domain, users[SvrName].UserName));
}
else
{
lbIDs.Items.Add(String.Format("{0}{1}{2}", SvrName, spaces, users[SvrName].UserName));
}
}
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
String SvrName = "";
Credentials cred = new Credentials();
while (true)
{
PasswordForm passForm = new PasswordForm();
if (passForm.ShowDialog() == DialogResult.OK)
{
SvrName = passForm.Machine;
SvrName = SvrName.ToUpper();
if (users.ContainsKey(SvrName))
{
MessageBox.Show("Error, a Username/Password already exists for " + SvrName);
return;
}
cred.UserName = passForm.UserName;
cred.Password = Program.GetEncodedPassword(passForm.Password);
cred.Domain = passForm.Domain;
if (cred.UserName.Length <= 0)
{
MessageBox.Show("You must put in a username!");
continue;
}
if (cred.Password.Length <= 0)
{
MessageBox.Show("You must put in a password!");
continue;
}
if (SvrName.Length <= 0)
{
MessageBox.Show("You must put in a Machine!");
continue;
}
break;
}
else
{
return;
}
}
users[SvrName] = cred;
RefreshLB();
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (lbIDs.SelectedIndex == -1) return;
String selItem = lbIDs.SelectedItem.ToString(); ;
String SvrName = selItem.Substring(0, selItem.IndexOf('\t'));
if(SvrName != "Default" )
SvrName = SvrName.Trim().ToUpper();
Credentials cred = users[SvrName];
PasswordForm passForm = new PasswordForm();
passForm.UserName = cred.UserName;
//pForm.Password = users[SvrName].Password;
passForm.Domain = cred.Domain;
passForm.Machine = SvrName;
if(SvrName == "Default") passForm.DisMachineCtrl = true;
while (true)
{
passForm.ShowDialog();
if (passForm.DialogResult == DialogResult.OK)
{
string newSvrName = passForm.Machine;
if (!users.ContainsKey(newSvrName))
{
users.Remove(SvrName);
users[newSvrName] = cred;
}
SvrName = newSvrName;
cred.UserName = passForm.UserName;
cred.Password = Program.GetEncodedPassword(passForm.Password);
cred.Domain = passForm.Domain;
if (cred.UserName.Length <= 0)
{
MessageBox.Show("Username can not be blank!");
continue;
}
if (cred.Password.Length <= 0)
{
MessageBox.Show("Password can not be blank!");
continue;
}
if (SvrName.Length <= 0)
{
MessageBox.Show("Machine must not be blank!");
continue;
}
break;
}
else
{
return;
}
}
RefreshLB();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (lbIDs.SelectedIndex <= 0) return;
String selItem = lbIDs.SelectedItem.ToString();
String SvrName = selItem.Substring(0, selItem.IndexOf('\t'));
SvrName = SvrName.Trim();
users.Remove(SvrName);
RefreshLB();
}
private void PassManage_Shown(object sender, EventArgs e)
{
RefreshLB();
}
private void btnOK_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}