-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (43 loc) · 1.49 KB
/
Copy pathmain.cpp
File metadata and controls
55 lines (43 loc) · 1.49 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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
// Function to generate a strong password
string generatePassword(int length, bool useSpecialCharacters, bool useSpacing) {
string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
if (useSpecialCharacters) {
characters += "!@#$%^&*()-_+=~`[]{}|;:,.<>?";
}
if (useSpacing) {
characters += " ";
}
string password;
int charactersSize = characters.size();
srand(time(nullptr));
for (int i = 0; i < length; ++i) {
password += characters[rand() % charactersSize];
}
return password;
}
int main() {
int length;
bool useSpecialCharacters, useSpacing;
// Question 1: Password length
cout << "How many characters do you want your password to have? (Recommendation: more than 10 characters): ";
cin >> length;
// Question 2: Use special characters
char response;
cout << "Can we use special characters? (y/n): ";
cin >> response;
useSpecialCharacters = (response == 'y' || response == 'Y');
// Question 3: Use spacing between characters
cout << "Can we use spacing between characters? (y/n): ";
cin >> response;
useSpacing = (response == 'y' || response == 'Y');
// Generate password
string password = generatePassword(length, useSpecialCharacters, useSpacing);
// Print password
cout << "Your generated strong password is: " << password << endl;
return 0;
}