#include #include #include #include #include /* rand_passwd.c * author: greg hamerly (greg_hamerly at baylor dot edu) * * This program chooses a random password for you. Don't like the password it * chooses? Run it again. I know, this is a stupidly simple program, but I have * found it useful. * * Copyright (C) 2002 Greg Hamerly (greg_hamerly at baylor dot edu) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/copyleft/gpl.html */ /* You can use whatever printable characters you like, but I have reduced the * set that is available because international keyboards can make it hard to * type passwords which have less-common characters. * * char *PRINTABLE_CHARS = "`1234567890-=~!@#$%^&*()_+qwertyuiop[]\\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"; */ char *PRINTABLE_CHARS = "123456789qwertyuipasdfghjklzxcvbnm"; int main(int argc, char **argv) { int numChars, numPrintable; int i; if (argc != 2) { fprintf(stderr, "usage: %s num_chars\n", argv[0]); exit(1); } srand(time(0)); numChars = atoi(argv[1]); assert(numChars > 0); numPrintable = strlen(PRINTABLE_CHARS); printf("new password is: "); for (i = 0; i < numChars; i++) { printf("%c", PRINTABLE_CHARS[rand() % numPrintable]); } printf("\n"); return 0; }