-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckArgs.cpp
More file actions
168 lines (94 loc) · 2.93 KB
/
Copy pathcheckArgs.cpp
File metadata and controls
168 lines (94 loc) · 2.93 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
// checkArgs.cpp - Checks command line arguments
#include "passwordNarrower.hpp"
#include "modifiers.hpp"
#include <string>
#include <sstream>
void help();
void usage();
void PasswordNarrower::checkArgs(int argc, char** argv) {
int argPos = 1; // Index value of current argument that is being parsed
while (argPos < argc) { // Repeats until all arguments have been parsed
std::string i = argv[argPos]; // argv must be converted to string for comparison
if (i == "-i") { // specifies input file
input = argv[argPos + 1]; // sets input to next argument
argPos += 2; // changes the argument position to one after the input
inputted = 1; // Sets flag so program knows there is an input file
}
else if (i == "-o") { // specifies output file
output = argv[argPos + 1];
argPos += 2;
outputted = 1;
}
else if (i == "--password") { // specifies password, if you know part of it
tempPass = argv[argPos + 1];
argPos += 2;
updateArgs(Modifiers::Password, 1);
}
else if (i == "--nums-only") { // only adds number passwords to the new file
argPos++;
updateArgs(Modifiers::NumsOnly, 1);
}
else if (i == "--chars-only") { // Only adds character passwords to the new file
argPos++;
updateArgs(Modifiers::CharsOnly, 1);
}
else if (i == "--upper-only") { // only adds uppercase passwords to the new file
argPos++;
updateArgs(Modifiers::UpperOnly, 1);
}
else if (i == "--lower-only") { // only adds lowercase passwords to the new file
argPos++;
updateArgs(Modifiers::LowerOnly, 1);
}
else if (i == "-n") { // skips over passwords with numbers
argPos++;
updateArgs(Modifiers::NoNums, 1);
}
else if (i == "-c") { // skips over passwords with characters
argPos++;
updateArgs(Modifiers::NoChars, 1);
}
else if (i == "-l") { // skips over passwords with lowercase characters
argPos++;
updateArgs(Modifiers::NoLow, 1);
}
else if (i == "-u") { // skips over passwords with uppercase characters
argPos++;
updateArgs(Modifiers::NoUp, 1);
}
else if (i == "-s") { // skips over passwords with special characters
argPos++;
updateArgs(Modifiers::NoSpecial, 1);
}
else if (i == "--max-length") { // sets maximum password length
std::stringstream stream;
stream << argv[argPos + 1];
stream >> maxLength;
argPos += 2;
}
else if (i == "--min-length") { // sets minimum password length
std::stringstream stream;
stream << argv[argPos + 1];
stream >> minLength;
argPos += 2;
}
else if (i == "--length") { // sets definite password length
std::stringstream stream;
stream << argv[argPos + 1];
stream >> length;
updateArgs(Modifiers::Length, 1);
argPos += 2;
}
else if (i == "--help") { // shows help dialog
argPos = argc;
helped = 1;
help();
}
else
argPos++;
}
if (!inputted || !outputted) { // without an input/output, the program can't run. Shows usage dialog.
usage();
exit(1);
}
}