-
Notifications
You must be signed in to change notification settings - Fork 1
/
PasswordGenerator.cpp
50 lines (37 loc) · 1.57 KB
/
PasswordGenerator.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
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <random>
using namespace std;
int main() {
cout << "Welcome to Password Generator" << endl;
int num_letters, num_numbers, num_symbols;
cout << "How many letters do you want in your password? ";
cin >> num_letters;
cout << "How many numbers do you want in your password? ";
cin >> num_numbers;
cout << "How many symbols do you want in your password? ";
cin >> num_symbols;
string letters_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string letters_lower = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
string symbols = "!@#$%^&*()_+-=[]{}|;:',.<>?";
// Seed the random number generator using time
mt19937 generator(time(0));
// Shuffle each category separately
shuffle(letters_upper.begin(), letters_upper.end(), generator);
shuffle(letters_lower.begin(), letters_lower.end(), generator);
shuffle(numbers.begin(), numbers.end(), generator);
shuffle(symbols.begin(), symbols.end(), generator);
// Select the desired number of characters from each category
string password = letters_upper.substr(0, num_letters) +
letters_lower.substr(0, num_letters) +
numbers.substr(0, num_numbers) +
symbols.substr(0, num_symbols);
// Shuffle the password string to ensure randomness
shuffle(password.begin(), password.end(), generator);
// Output the generated password
cout << "This is your password requirements: " << password << endl;
return 0;
}