-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword_Generator.cs
More file actions
167 lines (130 loc) · 4.38 KB
/
Password_Generator.cs
File metadata and controls
167 lines (130 loc) · 4.38 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace PasswordGeneratorApp
{
public partial class Password_Generator : Form
{
public bool check_box = false;
public Password_Generator()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Generator generator = new Generator();
Generated_password.Text = generator.Pass_roll(Password_length.Text, check_box);
}
private void Save_to_txt_button_Click(object sender, EventArgs e)
{
if(Pass_txt_name.Text == "")
{
}
else
{
saveFile(Generated_password.Text, Pass_txt_name.Text);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void saveFile(string input, string title)
{
string dirParameter = AppDomain.CurrentDomain.BaseDirectory + @"\" + title + ".txt";
FileStream fParameter = new FileStream(dirParameter, FileMode.Create, FileAccess.Write);
StreamWriter m_WriterParameter = new StreamWriter(fParameter);
m_WriterParameter.BaseStream.Seek(0, SeekOrigin.End);
m_WriterParameter.Write(input);
m_WriterParameter.Flush();
m_WriterParameter.Close();
System.Windows.Forms.MessageBox.Show("File saved");
}
private void Password_length_TextChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Generated_password_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void Pass_txt_name_TextChanged(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
check_box = !check_box;
}
}
public class Functions
{
public string Generate(int pass_length, string password, string characters, char[] letter_array, bool check_box, string normal_letters)
{
Random random = new Random();
if (check_box == true)
{
for (int i = 0; i < pass_length; i++)
{
password += letter_array[random.Next(0, letter_array.Length - 1)];
}
}
else
{
for (int i = 0; i < pass_length; i++)
{
password += normal_letters[random.Next(0, normal_letters.Length - 1)];
}
}
return password;
}
}
public class Generator
{
public string Pass_roll(string pass_length, bool check_box)
{
string password = "";
string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
string specChar = "!#$%&'()*+-/:;<=?@[_{|~";
string allCharacters = letters + specChar;
char[] array_of_characters = allCharacters.ToCharArray();
Functions instance = new Functions();
int length = 0;
try
{
length = Convert.ToInt32(pass_length);
}
catch (System.FormatException)
{
}
password = instance.Generate(length, password, allCharacters, array_of_characters, check_box, letters);
return password;
}
}
}