-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneratePasswords.cs
101 lines (95 loc) · 3.81 KB
/
GeneratePasswords.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
using System;
using System.Web.Security;
using System.IO;
using System.Windows.Forms;
namespace PGENV3
{
public partial class GeneratePasswords : Form
{
public GeneratePasswords()
{
InitializeComponent();
}
private void BtnGeneratePWD_Click(object sender, EventArgs e)
{
int length = int.Parse(NUDCharsInput.Text);
int num = int.Parse(NUDNumInput.Text);
pwdOutput.Clear();
LblProceeding.ResetText();
try
{
for (int i = 0; i < num; i++)
{
string password = Membership.GeneratePassword(length, length / 3).Replace('.', '?').Replace(';', '!').Replace(':', '#').Replace('_', '}');
pwdOutput.AppendText(password + Environment.NewLine);
LblProceeding.Text = "Done!";
}
pwdOutput.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BtnCopyPWD_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(pwdOutput.Text))
{
Clipboard.SetText(pwdOutput.Text);
NUDCharsInput.Value = NUDCharsInput.Minimum;
NUDNumInput.Value = NUDNumInput.Minimum;
pwdOutput.Clear();
LblProceeding.ResetText();
pwdOutput.Visible = false;
MessageBox.Show("Password Copied!", "P-GEN", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("There is no password to copy!", "P-GEN", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BtnExportPWD_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (!string.IsNullOrEmpty(pwdOutput.Text) && saveFileDialog.ShowDialog() == DialogResult.OK)
{
using (StreamWriter sw = new StreamWriter(saveFileDialog.FileName))
{
sw.Write(pwdOutput.Text);
MessageBox.Show("Passwords successfully exported to TXT file!", "P-GEN", MessageBoxButtons.OK, MessageBoxIcon.Information);
NUDCharsInput.Value = NUDCharsInput.Minimum;
NUDNumInput.Value = NUDNumInput.Minimum;
pwdOutput.Clear();
LblProceeding.ResetText();
pwdOutput.Visible = false;
}
}
else
{
MessageBox.Show("There is no passwords to export!", "P-GEN", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BtnClearInputs_Click(object sender, EventArgs e)
{
NUDCharsInput.Value = NUDCharsInput.Minimum;
NUDNumInput.Value = NUDNumInput.Minimum;
pwdOutput.Clear();
LblProceeding.ResetText();
pwdOutput.Visible = false;
MessageBox.Show("All inputs are reset!", "P-GEN", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void NUDCharsInput_MouseDown(object sender, MouseEventArgs e)
{
toolTip1.Show("Minimum is 12 and Maximum is 96!", this.NUDCharsInput);
}
private void NUDNumInput_MouseDown(object sender, MouseEventArgs e)
{
toolTip1.Show("Minimum is 1 and Maximum is 96!", this.NUDNumInput);
}
private void BtnExit_Click(object sender, EventArgs e)
{
Close();
}
}
}