-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.cpp
327 lines (303 loc) · 7.71 KB
/
tool.cpp
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#include <iostream>
using namespace std;
int main()
{
cout << "............................................" << '\n';
cout << ".. Password Vulnerability Checker .." << '\n';
cout << "............................................" << '\n';
cout << "\n";
cout << "Enter your password : ";
string pass;
getline(cin, pass);
int str_len = 0, special_char = 0, numbers = 0;
int lower_case = 0, upper_case = 0;
int spaces = 0, contiguous = 0, partial = 0;
string common[] = {"asdfghjkl;'", "asdfghjkl;", "asdfghjkl", "';lkjhgfdsa", "qwertyuiop[]", "zxcvbnm,./", "qwertyuiop", "lkjhgfdsa", ";lkjhgfdsa", "poiuytrewq", "[poiuytrewq", "][poiuytrewq", "/.,mnbvcxz", "ASDFGHJKL:\"", "QWERTYUIOP{}", "}{POIUYTREWQ", "\":LKJHGFDSA", "?><MNBVCXZ", "ZXCVBNM<>?"};
// Calculating Password length
while (pass[str_len] != '\0')
str_len++;
// Reference : https://cybernews.com/best-password-managers/how-to-create-a-strong-password/
string special_Char = "!#$%&'@()*+,-./:; <=>?[]^_`{|}~\\\"";
for (int i = 0; i < str_len; ++i)
{
for (int j = 0; j < (int)special_Char.length(); ++j)
{
// Calculating special Characters
if (pass[i] == special_Char[j])
{
special_char++;
}
}
// Calculating numbers
if ((pass[i] - '0' >= 0) && (pass[i] - '0' <= 9))
{
numbers++;
}
}
for (int i = 0; i < str_len; ++i)
{
// Calculating Upper Case letters
if (pass[i] >= 'A' && pass[i] <= 'Z')
{
upper_case++;
}
// Calculating Lower Case letters
else if (pass[i] >= 'a' && pass[i] <= 'z')
{
lower_case++;
}
}
// Test 1 : Contineous characters in the password
for (int i = 0; i <= str_len - 2; ++i)
{
if (pass[i] == pass[i + 1])
{
contiguous++;
}
else if (abs(pass[i] - pass[i + 1]) == 1)
{
if (!(((pass[i] >= ' ') && (pass[i] <= '/')) || ((pass[i] >= '[') && (pass[i] <= '`'))))
{
contiguous++;
}
else
{
partial++;
}
}
}
int maximum_contiguous = 0, temp = 0;
for (int i = 0; i <= str_len - 2; ++i)
{
if (abs(pass[i] - pass[i + 1]) < 2)
{
temp++;
}
else
{
maximum_contiguous = max(maximum_contiguous, temp);
temp = 0;
}
}
maximum_contiguous = max(maximum_contiguous, temp) + 1;
// Test 2 : Counting spaces in the password
for (int i = 0; i < str_len; ++i)
{
if (pass[i] == ' ')
{
spaces++;
}
}
// Verdict based on Higher priority and their numbers
// length (7) + upper (4) + lower (2) + special (4) + numbers (3) = 20
int index = 0;
// Full marks 7 in length test
if (str_len <= 5)
{
index += 3;
}
else if (str_len <= 10)
{
index += 5;
}
else
{
index += 7;
}
// Full marks 4 in upper case test
if (upper_case == 1)
{
index += 1;
}
else if (upper_case == 2)
{
index += 2;
}
else if (upper_case == 3)
{
index += 3;
}
else if (upper_case > 3)
{
index += 4;
}
// Full marks 2 in lower case test
if (lower_case >= 3)
{
index += 2;
}
else
{
index += 1;
}
// Full mark 4 in special test
if (special_char == 1)
{
index += 1;
}
if (special_char == 2)
{
index += 2;
}
else if (special_char == 3)
{
index += 3;
}
else if (special_char > 3)
{
index += 4;
}
// Full marks 3 in numbers
if (numbers >= 5)
{
index += 3;
}
else if (numbers >= 3)
{
index += 2;
}
else
{
index += 1;
}
// Sanitizer checking in the password
bool flag = false;
for (auto i : common)
{
if (i == pass)
{
flag = true;
break;
}
}
if (flag)
{
index -= 8;
}
else if (contiguous >= 5 && maximum_contiguous >= 5)
{
index -= 8;
}
// Verdict about the passwords strength
cout << "Judgement of the password [\u001b[33m" << pass << "\u001b[0m]" << '\n';
cout << "=> ";
if (str_len <= 5)
{
cout << "\u001b[31mExtremely weak password" << '\n';
}
else if (str_len <= 7)
{
cout << "\u001b[31mWeak Password" << '\n';
}
else if (index >= 15)
{
cout << "\u001b[32mStrong Password" << '\n';
}
else if (index >= 10)
{
cout << "\u001b[33mFair Password" << '\n';
}
else if (index >= 7)
{
cout << "\u001b[31mWeak Password" << '\n';
}
else
{
cout << "\u001b[31mExtremely Weak Password" << '\n';
}
// Comment about the password's strength
int i = 1;
bool check = true;
cout << "\u001b[35m";
if (str_len <= 10)
{
cout << "Comment #" << i << ": ";
cout << "You should create a lengthy password resulting a higher permutation number." << '\n';
i++;
check = false;
}
if (partial >= 4)
{
cout << "Comment #" << i << ": ";
cout << "\u001b[31mSpoiler : The special characters you used are contiguos in ascii value." << '\n';
cout << " Most likely it will be on the Wordlist of Kali.\u001b[35m" << '\n';
i++;
check = false;
}
if (flag)
{
cout << "Comment #" << i << ": ";
cout << "\u001b[31mFound using common QWERTY Keyboard combination which is in the Kali Wordlist file.\u001b[35m" << '\n';
i++;
check = false;
}
if (contiguous >= 5 && maximum_contiguous >= 4)
{
cout << "Comment #" << i << ": ";
cout << "Contiguous characters makes your password valnerable to hackers through bruteforce attack." << '\n';
i++;
check = false;
}
if (spaces >= 3)
{
cout << "Comment #" << i << ": ";
cout << "Careful about remembering the spaces you entered." << '\n';
i++;
check = false;
}
if (special_char >= 5)
{
cout << "Comment #" << i << ": ";
cout << "Careful about remembering the special characters you entered." << '\n';
i++;
}
if (special_char <= 2)
{
cout << "Comment #" << i << ": ";
cout << "Try to add more special characters." << '\n';
i++;
check = false;
}
if (numbers <= 4)
{
cout << "Comment #" << i << ": ";
cout << "Try to add more numbers in the password." << '\n';
i++;
check = false;
}
if (upper_case + lower_case <= 5)
{
cout << "Comment #" << i << ": ";
cout << "Try to include more alphabets in the password." << '\n';
i++;
check = false;
}
if (upper_case <= 3)
{
cout << "Comment #" << i << ": ";
cout << "Try to add more upper case letters in the password." << '\n';
i++;
check = false;
}
if (lower_case <= 4)
{
cout << "Comment #" << i << ": ";
cout << "Try to add more lower case letters in the password." << '\n';
i++;
check = false;
}
if (abs(numbers - str_len) <= 1)
{
cout << "Comment #" << i << ": ";
cout << "Using numbers only can exploit you to bruteforce attack." << '\n';
i++;
check = false;
}
if (check)
{
cout << "Comment #" << i << ": ";
cout << "WOW! A Strong password indeed." << '\n';
}
cout << "\u001b[0m";
return 0;
}