jeudi 14 janvier 2016

Creating a random password via reading data from a text file in C++

I am trying to create a program that allows a user to enter the kind of password they want (such as having the characters/letters/numbers they want) but am stuck at the random string generation part of the programming code.

#include <iostream>
#include <fstream>
#include <iomanip>  //ignore this at the moment, manipulators have not been used
#include <ctime>
#include <string>
#include <cstdlib>

using namespace std;
void main()
{
cout<<"Welcome to the Random Password Generator."<<endl<<
    "This application will generate a password with the inputs given by you."<<endl<<
    "Application will generate a password up to 16 characters long."<<endl;

ofstream outFile;
const int maxchar = 16;
string input;

cout<<"Please input the characters/numbers/symbols you want in the password: ";
cin>>input;

while (input.size() > maxchar)
{
    cout<<"Input is more than 16 characters. Please try again."<<endl;
    cin>>input;
}

outFile.open("Password Type.txt");
    if (!outFile)
        cout<<"Unable to open the requested .txt file";
    else 
    {
        outFile<<input<<endl;
        cout<<"Password Type.txt has been overwritten!"<<endl;
    }
    outFile.close();


ifstream inFile;
inFile.open("Password Type.txt");
if (!inFile)
    cout<<"Unable to open requested file."<<endl;
else
{
    while (!inFile.eof())
    {
        inFile>>input;
    }


    string randomPassword;

    for (int i = 0; i < input.size(); i++)
    {
        srand(time(NULL));

**[currently stuck here on how to randomize the string in the text file whereby the user has input-ed the data earlier on.]**

    }
    cout<<"Your random password generated is "<<randomPassword<<endl;
}           

system("pause");
}




Aucun commentaire:

Enregistrer un commentaire