-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator.cpp
More file actions
44 lines (31 loc) · 1.16 KB
/
Copy pathpassword_generator.cpp
File metadata and controls
44 lines (31 loc) · 1.16 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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0));
char repeat;
do {
string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{}|;:,.<>?";
string password = "";
int length;
cout << "\n**** Secure Password Generator ****" << endl;
cout << "Enter the password length: ";
cin >> length;
if (length <= 0) {
cout << "Password length must be a positive number greater than 0." << endl;
} else {
for (int i = 0; i < length; i++) {
int randomIndex = rand() % characters.length();
password += characters[randomIndex];
}
cout << "\nYour randomlygenerated password is: " << password << endl;
cout << "- - - - - - - - - - - - - - - -" << endl;
}
cout << "\nWould you like to get another randomly generated password? (y/n): ";
cin >> repeat;
} while (repeat == 'y' || repeat == 'Y');
cout << "\nSee you next time!" << endl;
return 0;
}