-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp83_Random_Password_Generator.cpp
More file actions
26 lines (22 loc) · 978 Bytes
/
Copy pathp83_Random_Password_Generator.cpp
File metadata and controls
26 lines (22 loc) · 978 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
#include <bits/stdc++.h>
using namespace std;
char charecters[] = "0123456789!@#$%^&*qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; // array of charecters
int main()
{
int length_of_password, len_of_char_array = sizeof(charecters); // length of char array
cout << "Enter the length of Password: ";
cin >> length_of_password; // Desired length input
srand(time(NULL)); // initialize the random according to the current time of computer
cout << "Random Generated Password: ";
string password;
for (int i = 0; i < length_of_password; i++) // to print random charecter from the defined array
{
password = password + charecters[rand() % len_of_char_array]; // length of charecter array(No of charecters we have defined)
}
cout << password << "\n";
ofstream file;
file.open("Password_file.txt");
file << password; // saving password to text file
file.close();
return 0;
}