Code:
/*
pwgenCL version 2 (pwgenCL_2)Copyright (C) 2004 Scorpius, password generator,
written as a command line scripting utility.
this program is freesource, which means you may use and/or modify it under the GPL license.
if you'd like to contact me with comments/bugs/suggestions or just to say hello,
my email address is: [email protected].
i hope you enjoy using my program and that you find it usefull :)
to compile it under windows, get a copy of Dev-C++ (it's free), or another C/C++ compiler.
to compile it under linux, just type "gcc -o pwgenCL_2 pwgenCL_2.c" (without the " quotes)
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <strings.h>
char *generated_password(char*, int,int);
int main(int argc, char** argv)
{ /*the character sets*/
char *very_easy_set = "abcdefghijklmnopqrstuvwxyz";
char *very_easy2_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *easy_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *medium_set = "abcdefghijklmnopqrstuvwxyz0123456789";
char *hard_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *hard2_set = "\\][^_abcdefghijklmnopqrstuvwxyz0123456789";
char *very_hard_set = "!\"#$%'(*)+,-./abcdefghijklmnopqrstuvwxyz0123456789";
char *extreme_set = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
int characterset=0;
int password_length=0;
int user_supplied=0;
if(argc!=4)
{
printf("\npwgenCL_2,commandline password generator, Copyright (C) 2004 Scorpius");
printf("\n\npwgenCL_2 is free software; you can redistribute it and/or modify");
printf("\nit under the terms of the GNU General Public License as published by");
printf("\nthe Free Software Foundation; either version 2 of the License.");
printf("\n\npwgenCL_2 is distributed in the hope that it will be useful,");
printf("\nbut WITHOUT ANY WARRANTY; without even the implied warranty of");
printf("\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
printf("\nGNU General Public License for more details.");
printf("\n\nYou should have received a copy of the GNU General Public License");
printf("\nalong with this program; if not, write to the Free Software");
printf("\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
printf("\n\t ***Contact Scorpius: [email protected]***");
printf("\n\nCharacter sets:");
printf("\n1: (a-z)\t\t\t\t\tvery easy password");
printf("\n2: (A-Z)\t\t\t\t\tvery easy password");
printf("\n3: (a-z,A-Z)\t\t\t\t\teasy password");
printf("\n4: (a-z,0-9)\t\t\t\t\tmedium password");
printf("\n5: (A-Z,a-z,0-9)\t\t\t\thard password");
printf("\n6: (a-z,0-9, \\ ] [ ^ _ )\t\t\thard password");
printf("\n7: ( ! \" # $ % ' ( * ) + , - . / ,a-z,0-9)\tvery hard password");
printf("\n8: full keyboard characters (except space), almost impossible to crack\n\n");
printf("The maximum password length is 256 characters\n");
printf("Usage: %s <characterset> <password length> <user supplied number>\n",argv[0]);
printf("\n*The <user supplied number> is inserted to create extra randomness*\n");
printf("\nExample: %s 8 15 5454303\n",argv[0]);
return 0;
}
if(argc==4)/*if all parameters, (characterset,passwordlength,randomization number) run the program*/
{
characterset=atoi(argv[1]);/*create integer from the argument*/
password_length=atoi(argv[2]);/*create integer from the argument*/
user_supplied=atoi(argv[3]);/*create integer from the argument*/
if (password_length<1)
{
printf("Password length: %d is too small.\n",password_length);
return -1;
}
if (password_length>256)
{
printf("Password length: %d is too large.\n",password_length);
return -1;
}
switch(characterset)
{
case 1:
generated_password(very_easy_set,password_length,user_supplied);
break;
case 2:
generated_password(very_easy2_set,password_length,user_supplied);
break;
case 3:
generated_password(easy_set,password_length,user_supplied);
break;
case 4:
generated_password(medium_set,password_length,user_supplied);
break;
case 5:
generated_password(hard_set,password_length,user_supplied);
break;
case 6:
generated_password(hard2_set,password_length,user_supplied);
break;
case 7:
generated_password(very_hard_set,password_length,user_supplied);
break;
case 8:
generated_password(extreme_set,password_length,user_supplied);
break;
default:
printf("Invalid character set\n");
return -1;
break;
}
return 0;
}
else return -1;
}
/*the password generator function*/
char *generated_password(char* char_set, int length,int user_number)
{
srand(user_number*time(NULL));
int loop;
int set_length=strlen(char_set);
for(loop=0;loop<length;loop++)
{
putchar(char_set[rand()%set_length]);
}
printf("\n");
}
(b.t.w., it is opensource, feel free to use the program/alter the code under the GPL license)