Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <Windows.h>
- #include <chrono>
- #include <random>
- int main(){
- int length = 0;
- char* file = "Password_Output.txt";
- typedef std::chrono::high_resolution_clock myclock;
- myclock::duration c_time = myclock::now().time_since_epoch();
- std::mt19937 generator(c_time.count() ^ GetCurrentProcessId());
- std::cout << "Write number of charachters the password must have: ";
- std::cin >> length;
- if (!std::cin.good()) {
- std::cout << "Not a valid input." << std::endl;
- system("PAUSE>NUL");
- return 0;
- }
- char*password = new char[length + 1];
- for (int i = 0; i < length; i++) password[i] = (generator() % 95) + 32;
- password[length] = 0;
- std::ofstream myfile;
- myfile.open(file);
- if (myfile.is_open()){
- myfile << password;
- myfile.close();
- std::cout << "Password written to file: " << file << std::endl;
- }
- else{
- std::cout << "Failed to create and open file " << file << std::endl;
- }
- delete[] password;
- system("PAUSE>NUL");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement