+ 1

Password Gen inc File Saving And Clipboard Saving

So finally got my password generator to work. #include <iostream> #include <stdlib.h> #include <string> #include <time.h> #include <cstdlib> #include <cstring> #include <fstream> #include <ctime> #include <Windows.h> using namespace std; void copytoclip(string stringpassword) { //Saves to ClipBoard const char * c = stringpassword.c_str(); //Sets the clipboard with the varaible wanting to save const size_t len = strlen(c) + 1; HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len); memcpy(GlobalLock(hMem), c, len); GlobalUnlock(hMem); OpenClipboard(0); EmptyClipboard(); SetClipboardData(CF_TEXT, hMem); CloseClipboard(); } void savePassword(string stringpassword, string site) { string path = string(getenv("USERPROFILE")) + "\\Documents\\output.txt"; // Gets the user profile to save too. ofstream out(path, ofstream::app); // Here out << site << ": " << stringpassword << endl; // This is where it saves the password into the text file out.close(); // Closes file cout << "File Saved" << endl; } int passwordgen() { system("CLS"); string stringpassword; // New string for password srand((unsigned)time(0)); // Sets up for a random time int randomnum; // Just a varible for randomnumber string site; cout << "What site/program do you want this password for? "; cin >> site; Sleep(500); system("CLS"); for (int i = 0; i < 13; i++) // Loop 0-12 { randomnum = (rand() % 89) + 65; // Generates between 65 and 122 (65+58=123 because you need 1 more.) do { randomnum = (rand() % 89) + 33; // Generates between 65 and 122 (65+58=123 because you need 1 more.) } while ((randomnum >= 32 && randomnum <= 41) || (randomnum >= 58 && randomnum <= 64) || (randomnum >= 91 && randomnum <= 96)); // Keeps generating until there is a valid number stringpassword += randomnum; // Adds the character to the string } // for loop cout << "Password Is: " << stringpassword << endl << endl << "Password Copied to clipboard" << endl << endl; savePassword(stringpassword, site); copytoclip(stringpa

21st Feb 2017, 4:42 PM
James Smith
1 Réponse