-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
32 lines (25 loc) · 865 Bytes
/
Copy pathmain.cpp
File metadata and controls
32 lines (25 loc) · 865 Bytes
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
std::string generatePassword(int length) {
std::string password;
const std::string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
int charCount = characters.length();
// Initialize random number generator
std::srand(static_cast<unsigned int>(std::time(nullptr)));
// Generate random password
for (int i = 0; i < length; ++i) {
int index = std::rand() % charCount;
password += characters[index];
}
return password;
}
int main() {
int passwordLength;
std::cout << "Enter the desired length for the password: ";
std::cin >> passwordLength;
std::string password = generatePassword(passwordLength);
std::cout << "Generated Password: " << password << std::endl;
return 0;
}