-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (66 loc) · 2.56 KB
/
Program.cs
File metadata and controls
69 lines (66 loc) · 2.56 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
using System.Text;
namespace PasswordGenerator
{
public static class RandomString
{
private static void Main(string[] args)
{
Console.Title = "Lilyy2565 Password Generator";
if (args.Length == 0)
{
bool lenError = false;
int len = 15;
while (true)
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.DarkMagenta;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" * Lilyy2565 Password Generator * ");
Console.ResetColor();
Console.WriteLine("Press [LARROW] or [RARROW] increase or decrease the amount of characters in the password.");
Console.WriteLine($"Current length: {len}\n");
if (lenError)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" ! Password cannot be of length less than 1.\n");
Console.ResetColor();
}
Console.WriteLine("Generated Password: " + Generate(len));
lenError = false;
var key = Console.ReadKey();
if (key.Key == ConsoleKey.RightArrow)
{
len++;
}
else if (key.Key == ConsoleKey.LeftArrow)
{
if (len == 1)
{
lenError = true;
}
else
{
len--;
}
}
}
}
else
{
Console.WriteLine(Generate(Convert.ToInt32(args[0])));
}
}
private static Random random = new Random();
public static string Generate(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*(){}[];:'@#~,<.>/?\\|-_=+`¬¦";
StringBuilder result = new StringBuilder(length);
for (int i = 0; i < length; i++)
{
result.Append(chars[random.Next(chars.Length)]);
}
return result.ToString();
}
}
}