-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·78 lines (67 loc) · 2.59 KB
/
Program.cs
File metadata and controls
executable file
·78 lines (67 loc) · 2.59 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
using System.Collections.Generic;
using System.IO;
using System;
using McMaster.Extensions.CommandLineUtils;
namespace PassCensor
{
[Command(Name = "PassCensor", Description = "Censors a list of passwords")]
[HelpOption("-H")]
public class Program
{
static void Main(string[] args) => CommandLineApplication.Execute<Program>(args);
[Argument(0, Description = "Path to the input file")]
private string path { get; }
[Argument(1, Description = "Path to the output file")]
private string output { get; }
private void OnExecute()
{
if (path != null && output != null)
{
string file;
List<string> censoredPasswords = new List<string>();
file = Path.GetFullPath(path);
using(StreamReader sr = new StreamReader(file))
{
while(!sr.EndOfStream)
{
string cred = sr.ReadLine();
string user = string.Empty;
string pass = string.Empty;
if (cred.Contains(':'))
{
user = cred.Substring(0, cred.IndexOf(":", StringComparison.Ordinal));
pass = cred.Substring(cred.IndexOf(":") + 1);
}
else
{
pass = cred;
}
char[] ch = pass.ToCharArray();
for(int i = 1; i < pass.Length - 1; i++)
{
ch[i] = '*';
}
pass = new string(ch);
if (String.IsNullOrEmpty(user))
{
censoredPasswords.Add(pass);
}
else
{
censoredPasswords.Add(user + ":" + pass);
}
}
}
using (StreamWriter outputFile = new StreamWriter(output))
{
censoredPasswords.ForEach(line => outputFile.WriteLine(line));
Console.WriteLine("Output saved at " + output);
}
}
else {
Console.WriteLine("You need to enter the input and output files");
Console.WriteLine("Example: PassCensor /path/to/input.txt /path/to/output.txt");
}
}
}
}