Hi have made some code that will generate alphanumeric passwords and output them into a file. Each password size has its own function so i have 16 functions for sizes 1-16. The code works great its just that as you go up one size in the password size it will increases the time it takes to process by a factor of 96. I was wondering if i was going the long way around or its just a lot of possibilities and I'm SOL

void PassList3()
{
	int counter = 0;
	char password[4];
	for (int i = 0; i < 4; i++)  // sets all char in the array to 0 before starting
	{
		password[i] = 0;
	}
	ofstream fout("Password List 3.txt");
	for (int place1 = 32; place1 < 128; place1++)  // using integer assignment to set the character
	{
		password[0] = place1;
		for (int place2 = 32; place2 < 128; place2++)
		{
			password[1] = place2;
			for (int place3 = 32; place3 < 128; place3++)
			{
				password[2] = place3;
				fout << password << "\n";
				cout << password << "\t\t" << counter << "\n";
				counter++;
			}
		}
	}
	fout.close();
	cout << "\nPasswords saved in: Password List 3.txt";
}

any help would be appreciated.

I don't know about faster, but here is another way that only requires a single function. This function only writes to the screen, not to a file.

#include <string>
#include <ctime>
using namespace std;

void Passwords(int size)
{
    std::string pwd;
    pwd.resize(size);
    for(int i = 0; i < 128; i++)
    {
        for(int j = 0; j < size; j++)
        {
            char c;
            // do not allow duplicates in the password
            do
            {
                c = 35 + (rand() % 91);
            } while ( pwd.find(c) != string::npos);
            pwd[j] = c;

        }
        cout << pwd << "\n";
    }

}

int main()
{
    srand( (unsigned int)time(0) );
    Passwords(15);

}

i see where your going but i want to make sure that i have every possible uppercase and lowercase alphanumeric string you can have in the list. also i know that there are also the characters the normal characters on the keyboard and i have them in there because sometimes they are used.

i see where your going but i want to make sure that i have every possible uppercase and lowercase alphanumeric string you can have in the list. also i know that there are also the characters the normal characters on the keyboard and i have them in there because sometimes they are used.

There are 62 alphanumeric characters ('0' - '9', 'a' - 'z', 'A' - 'Z'). If you want all the characters from ASCII 32 to ASCII 127, that's 96 characters. For an n-character string, that's 96^n possibilities. Thus, as you say, increasing the length by 1 increases the number of possibilities by 96, which will pretty much guarantee that it will take at least 96 times as long to generate all the possibilities as it did for the previous size. In fact, it will certainly take MORE than 96 times as long because each individual string will take longer to generate and longer to write to the file. It doesn't matter how you code it. That's why brute force methods of password cracking where you try every single possible password are so easy to counter. Just make the password a little longer and the time required to break it is exponentially longer.

That said, are you trying to find a way to generate all the possibilities using only a single function rather than 16 functions? And do you want all 96 characters or just the alphanumeric ones?

52040292466647269602037015248896
That's the size of your last file - are you sure you want to do this?

Y'know, some simple maths to determine whether your plan will actually yield a result in lets say the age of the universe?

commented: right on! +19
commented: Haha, great advice +17

i realized that the time required and the file size will be enormous at a length of 16 digits thats why i was asking but i guess there isn't a way to bypass the rules of a computer system is there? i didn't know though if i was going the completely wrong direction or if i was right and its just that this isn't a realistic thing to pull off.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.