-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
337 lines (291 loc) · 13.2 KB
/
MainForm.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using CsvHelper;
using System.Globalization;
using CsvHelper.Configuration;
using Microsoft.VisualBasic;
namespace The_vault
{
public partial class MainForm : Form
{
private int id = 0;
public MainForm()//we completly finished login/encryption/decryption/validation/etc etc i forgot, before i work on the main stuff im going to see what features other password vaults have
{
InitializeComponent();
Internals.initialize();
MessageBox.Show($"Welcome back, {Internals.grabusername()}!");//display username
if (File.Exists(@"Vault\accounts\accounts.csv"))
{
readcsv();
id = listView1.Items.Count;
}
else
{
Directory.CreateDirectory(@"Vault\accounts"); ;
}
lbltitleitems.Text = $"Logins Saved: {listView1.Items.Count}";
MessageBox.Show(Properties.Settings.Default.Key+"\n\n"+ Properties.Settings.Default.InitializationVector+"\n\n"+ Properties.Settings.Default.Pepper);
}
private static string updateitems(ListView l)
{
return $"Logins Saved: {l.Items.Count}";
}
private void GunaButton1_Click(object sender, EventArgs e)
{
// string pwd = "Click to reveal.";//dont store unencrypted password this is
bool valweb = Internals.validatewebsite(txtwebs.Text.ToLower());//they are both booleans so i could remove these to lower time and increase speed
bool vallgn = Internals.validateuserandpass(txtlgn.Text);//^
bool valps = Internals.validateuserandpass(txtpassw.Text);//^^
if (valweb == true)
{
if (vallgn == true & valps == true)
{
// string json = serialize.serilizeitems(id, txtwebs.Text, txtlgn.Text, txtpassw.Text, DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy"));
writecsv();//
try
{
var items = new ListViewItem(id.ToString());//create a list of items to add essentally
items.SubItems.Add(txtwebs.Text);//add wevsute to listbox
items.SubItems.Add(txtlgn.Text);//add login to listvbox
items.SubItems.Add(txtpassw.Text);//add pass
items.SubItems.Add(DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy"));//grab the date and time and add it
listView1.Items.Add(items);//add all of the items we created
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
Internals.writeerro(ex.Message);
}
}
else
{
MessageBox.Show("You must enter a valid login/password!");
}
}
else
{
MessageBox.Show("You must enter a valid website!");
}
lbltitleitems.Text = updateitems(listView1);//update every time they click da button
id++;
}
private void ListView1_DoubleClick(object sender, EventArgs e)
{
try
{
if (listView1.SelectedItems.Count > 0)// some validation
{
if (MessageBox.Show("Would you like to delte this value?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
listView1.SelectedItems[0].Remove();
}
else
{
MessageBox.Show("Okay!");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"A error appeared:{ex.Message}");
}
}
private void GunaControlBox1_Click(object sender, EventArgs e)
{
Application.ExitThread();
Application.Exit();
Environment.Exit(0);
}
public void readcsv()
{
using (var reader = new StreamReader(@"Vault\accounts\accounts.csv"))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<Items>().ToList();
foreach (var person in records)
{
var items = new ListViewItem(person.ID.ToString());//create a list of items to add essentally
items.SubItems.Add(Encoding.ASCII.GetString(Internals.decryptdata(Convert.FromBase64String(person.website), Internals.key, Internals.iv)));
items.SubItems.Add(Encoding.ASCII.GetString(Internals.decryptdata(Convert.FromBase64String(person.username), Internals.key, Internals.iv)));
items.SubItems.Add(Encoding.ASCII.GetString(Internals.decryptdata(Convert.FromBase64String(person.password), Internals.key, Internals.iv)));
items.SubItems.Add(Encoding.ASCII.GetString(Internals.decryptdata(Convert.FromBase64String(person.date), Internals.key, Internals.iv)));//grab the date and time and add it
listView1.Items.Add(items);//add all of the items we created
}
}
}
public void SaveCSV()
{
CsvConfiguration csvConfig = new CsvConfiguration(CultureInfo.CurrentCulture)
{
HasHeaderRecord = !File.Exists(@"Vault\accounts\accounts.csv")
};
var records = new List<Items> { };
/* foreach (ListViewItem listViewItem in listView1.Items)
{
records.Add(new Items { ID = id, website = _Web, username = _Usr, password = _Pass, date = _Date });//im lazy ill finsih later
}
*/
using (FileStream fileStream = new FileStream(@"Vault\accounts\accounts.csv", FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
using (var writer = new StreamWriter(fileStream))
using (var csv = new CsvWriter(writer, csvConfig))
{
csv.WriteRecords(records);
}
}
}
public void writecsv()
{
try
{
//convert all these values to bytes so that i can encrypt it later
byte[] _web = Encoding.ASCII.GetBytes(txtwebs.Text);
byte[] _usr = Encoding.ASCII.GetBytes(txtlgn.Text);
byte[] _lgn = Encoding.ASCII.GetBytes(txtpassw.Text);
byte[] _date = Encoding.ASCII.GetBytes(DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy"));
//encyrpt the bytes
String _Web = Convert.ToBase64String(Internals.encryptdata(_web, Internals.key, Internals.iv));
String _Usr = Convert.ToBase64String(Internals.encryptdata(_usr, Internals.key, Internals.iv));
String _Pass = Convert.ToBase64String(Internals.encryptdata(_lgn, Internals.key, Internals.iv));
String _Date = Convert.ToBase64String(Internals.encryptdata(_date, Internals.key, Internals.iv));
CsvConfiguration csvConfig = new CsvConfiguration(CultureInfo.CurrentCulture)
{
HasHeaderRecord = !File.Exists(@"Vault\accounts\accounts.csv")
};
var records = new List<Items> { };
records.Add(new Items { ID = id, website = _Web, username = _Usr, password = _Pass, date = _Date });
using (FileStream fileStream = new FileStream(@"Vault\accounts\accounts.csv", FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
using (var writer = new StreamWriter(fileStream))
using (var csv = new CsvWriter(writer, csvConfig))
{
csv.WriteRecords(records);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error! Please check error lo!");
Internals.writeerro(ex.Message);
}
}
private void Txtpassw_TextChanged(object sender, EventArgs e)
{
}
private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void GunaImageButton1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to nuke the applacation?\n This will delete all traces of your logins and login data!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
Properties.Settings.Default.Reset();
File.Delete(@"Vault\accounts\accounts.csv");
if (Directory.Exists(@"Vault"))
{
//Delete all files from the Directory
foreach (string file in Directory.GetFiles(@"Vault\accounts"))
{
File.Delete(file);
}
foreach (string file in Directory.GetFiles(@"Vault\login"))
{
File.Delete(file);
}
//Delete all child Directories
//Delete a Directory
Directory.Delete(@"Vault\accounts");
Directory.Delete(@"Vault\login");
Directory.Delete(@"Vault");
}
Application.Restart();
int a = 0;
if (MessageBox.Show("Done... Would you like to break the applacation aswell?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
while (true)
{
a++;
File.WriteAllText("File.txt", $"pumped {a}bytes");
}
}
Application.ExitThread();
Environment.Exit(0);
}
}
private void Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(@"6/1/2020 - Completed applacation
6/2/2020 - small update done");
}
private void PictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
PictureBox btnSender = (PictureBox)sender;
Point ptLowerLeft = new Point(0, btnSender.Height);
ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
contextMenuStrip1.Show(ptLowerLeft);
}
private void NukeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to nuke the applacation?\n This will delete all traces of your logins and login data!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
File.Delete(@"Vault\accounts\accounts.csv");
if (Directory.Exists(@"Vault"))
{
//Delete all files from the Directory
foreach (string file in Directory.GetFiles(@"Vault\accounts"))
{
File.Delete(file);
}
foreach (string file in Directory.GetFiles(@"Vault\login"))
{
File.Delete(file);
}
//Delete all child Directories
//Delete a Directory
Directory.Delete(@"Vault\accounts");
Directory.Delete(@"Vault\login");
Directory.Delete(@"Vault");
}
Application.Restart();
int a = 0;
if (MessageBox.Show("Done... Would you like to break the applacation aswell?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
while (true)
{
a++;
File.WriteAllText("File.txt", $"pumped {a}bytes");
}
}
else
{
Application.Restart();
}
Application.ExitThread();
Environment.Exit(0);
}
}
private void InformationToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show($"Username:{Internals.grabusername()} \nVersion:0.0.0.1\nTotal Saved passwords:{listView1.Items.Count} ", "The vault", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void CheckForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000);
MessageBox.Show("Your up to date!");
}
}
}