-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword_Generator.cpp
57 lines (51 loc) · 2 KB
/
Password_Generator.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
/**
* You can use this program to generate random passwords.
**/
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
cout << "\n---------------------------------------------------------------" << endl;
cout << " Hello, please enter the length of the password: ";
int passwordLength;
cin >> passwordLength;
string numeric = "0123456789";
string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string lowercase = "abcdefghijklmnopqrstuvwxyz";
string special = "()<>[]{}/!?*@#&$^%_-+=";
string password = "";
srand(time(0));
string select = "";
cout << "---------------------------------------------------------------" << endl;
cout << "| Choose the types of characters for the password: |" << endl;
cout << "| 1- Lowercase letters |" << endl;
cout << "| 2- Uppercase letters |" << endl;
cout << "| 3- Numeric digits |" << endl;
cout << "| 4- Special characters |" << endl;
cout << "---------------------------------------------------------------" << endl;
cout << " Enter your choices: ";
string choices;
cin >> choices;
if (choices.find("1") != string::npos) {
select += lowercase;
}
if (choices.find("2") != string::npos) {
select += uppercase;
}
if (choices.find("3") != string::npos) {
select += numeric;
}
if (choices.find("4") != string::npos) {
select += special;
}
for (int i = 0; i < passwordLength; i++) {
int random = rand() % select.length();
password += select[random];
}
cout << "---------------------------------------------------------------" << endl;
cout << "*** Generated Password: " << password << endl;
cout << "---------------------------------------------------------------" << endl;
return 0;
}