Password

Password is a command-line password generation program that can generate random passwords of any length containing letters and numbers. Password takes one parameter, a number indicating the length of password it should generate. As an example:

password 8

will generate an eight character long password.

Special requirements

Download

Known Problems

None.

Status

FreeWare.

Version Information

password-1.0.zip (v1.0) is the first version.

C++ Source Code

Here's the C++ source. Should be very easy to modify and port to whatever system you want. The only Windows-ism is GetTickCount() which is a Windows call to get the current uptime in milliseconds.


// Copyright 2002, Ted Felix
// Feel free to use for whatever.
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

int main(int argc, char *argv[], char * /*envp*/ [])
{
	if (argc == 1)
	{
		cout << "Usage: password size" << endl;
		return 1;
	}

	char *pDummy;
	// Get the password length from the first argument
	long iLength = strtol(argv[1], &pDummy, 10);

	// Seed the random number generator with the time
	srand(GetTickCount());

	// Throw away the first two.
	rand(); rand();

	// The list of possible password characters
	const char sChars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	int iCharCount = strlen(sChars);

	// For each character
	for (int I = 0; I < iLength; I++)
	{
		// Pick a random character
		int iChar = rand() * iCharCount / RAND_MAX;

		// Display the character
		cout << sChars[iChar];
	}
	// Write a newline for neatness
	cout << endl;
	return 0;
}

<- Back to SupaSoft.

Copyright ©2002, Ted Felix