-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPassword-Gen.cpp
74 lines (66 loc) · 2.09 KB
/
Password-Gen.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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <limits>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int size = sizeof(alphanum) - 1;
int main()
{
/* Password-Generator
Generate a strong password with a desired length!
*/
cout << "Generate a strong password!\nSelect a number from 8 to 15\n";
int length;
// Ask the user for the length of the password
// Length must be in between 8 to 15 characters
while (true)
{
cout << "Length of password: ";
cin >> length;
// Edge case if the user types a non-integer input
if (!cin)
{
cout << "Type only numbers between 8-15." << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
continue;
}
// Too short
else if (length < 8)
{
cout << "Length too short. Password length must be more than 8" << endl;
continue;
}
// Too long
else if (length > 15)
{
cout << "Length too long. Password length must be less than 15" << endl;
continue;
}
// If it passes all these tests, the user input is valid
else
{
break;
}
}
// Generate the password with a given length
cout << "---🔐Password Generated🔐----Copy below--------\n";
srand(time(0));
for (int i = 0; i < length; i++)
{
cout << alphanum[rand() % ::size];
}
cout << "\n";
cout << "-----------------------------------------------\n";
cout << "THANK YOU FOR USING MY TOOL :3 \n"<<endl;
cout << "-DROID\n";
cout << "░░░░░░░░░░░░░░░░░███████ ]▄▄▄▄▄▄▄▄▄-----------******\n";
cout << "░░░░░░░░░░░░▂▄▅█████████▅▄▃▂\n";
cout << "░░░░░░░░░░░I███████████████████].\n";
return 0;
}