-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
187 lines (171 loc) · 6.25 KB
/
Copy pathProgram.cs
File metadata and controls
187 lines (171 loc) · 6.25 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
using System;
using System.Diagnostics;
using System.IO;
using NAudio.Wave;
using System.Threading;
class Program
{
static string PasswordFile = "CSP.txt";
static string MusicPath = "music.flac";
static void Main()
{
Console.Title = "X-UPC";
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.Black;
Console.Clear();
// Fake loading animation
LoadingAnimation("BOOTING X-UPC");
// Play music in background thread
Thread musicThread = new Thread(PlayMusic);
musicThread.IsBackground = true;
musicThread.Start();
// Authentication loop
string correctPassword = File.Exists(PasswordFile) ? File.ReadAllText(PasswordFile).Trim() : "";
while (true)
{
Console.Write("Password: ");
string? input = Console.ReadLine()?.Trim();
if (string.IsNullOrEmpty(input) || input != correctPassword)
{
Console.WriteLine("INCORRECT PASSWORD\n");
continue;
}
break;
}
ShowMenu();
// Reset console colors before exit
Console.ResetColor();
}
static void ShowMenu()
{
while (true)
{
Console.Clear();
Console.WriteLine("***************");
Console.WriteLine(" MENU");
Console.WriteLine("***************\n");
Console.WriteLine("1) List Users On PC");
Console.WriteLine("2) Create A New User");
Console.WriteLine("3) Change A User's Pass");
Console.WriteLine("4) Delete A User Account");
Console.WriteLine("5) Change Script Pass");
Console.WriteLine("6) Exit X-UPC\n");
Console.Write("C:\\Users> ");
string? choice = Console.ReadLine()?.Trim();
switch (choice)
{
case "1":
RunCommand("net user");
break;
case "2":
Console.Write("Enter New User's Name: ");
string? newUser = Console.ReadLine()?.Trim();
Console.Write("Enter Password: ");
string? newPass = Console.ReadLine()?.Trim();
if (!Validate(newUser, newPass)) break;
RunCommand($"net user \"{newUser}\" \"{newPass}\" /add");
break;
case "3":
Console.Write("Enter User's Name: ");
string? targetUser = Console.ReadLine()?.Trim();
Console.Write("Enter New Password: ");
string? newPassword = Console.ReadLine()?.Trim();
if (!Validate(targetUser, newPassword)) break;
RunCommand($"net user \"{targetUser}\" \"{newPassword}\"");
break;
case "4":
Console.Write("Enter User's Name to DELETE: ");
string? delUser = Console.ReadLine()?.Trim();
if (string.IsNullOrEmpty(delUser)) break;
Console.Write($"Are you sure you want to delete '{delUser}'? (y/n): ");
string? confirm = Console.ReadLine();
if (confirm?.Trim().ToLower() == "y")
{
RunCommand($"net user \"{delUser}\" /delete");
Console.WriteLine($"User '{delUser}' deleted.");
}
else Console.WriteLine("Delete cancelled.");
break;
case "5":
Console.Write("Enter New Script Password: ");
string? scriptPass = Console.ReadLine()?.Trim();
if (string.IsNullOrEmpty(scriptPass)) break;
try
{
File.WriteAllText(PasswordFile, scriptPass);
Console.WriteLine("Password Updated!");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to update password: {ex.Message}");
}
break;
case "6":
return;
default:
Console.WriteLine("Invalid Option. Try again.");
break;
}
Console.WriteLine("\nPress any key to return to the menu...");
Console.ReadKey();
}
}
static void RunCommand(string command)
{
using (var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c " + command,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
})
{
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
process.WaitForExit();
}
}
static bool Validate(string? user, string? pass)
{
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(pass))
{
Console.WriteLine("User name or password cannot be empty.");
return false;
}
return true;
}
static void LoadingAnimation(string message)
{
Console.Write($"[{message}]");
for (int i = 0; i < 30; i++)
{
Thread.Sleep(40);
Console.Write(".");
}
Console.WriteLine("\n[READY]");
Thread.Sleep(500);
Console.Clear();
}
static void PlayMusic()
{
try
{
using var audio = new AudioFileReader(MusicPath);
using var output = new WaveOutEvent();
output.Init(audio);
output.Play();
while (output.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(500);
}
}
catch
{
// Ignore if music fails (missing file or wrong format)
}
}
}