[Semibug] Generate random passwords?

Mike Wayne semibug15 at post.wayne47.com
Fri Jul 16 14:57:29 EDT 2021


On Thu, Jul 15, 2021 at 01:40:15PM -0600, Jonathan Drews wrote:
> What is a good way to generate random passwords on OpenBSD? 

I rather despise having to install a package (or, much worse,
multiple packages) for something so simple.

An ex employee wrote this back in 1995:


/*
 * randpass.c -- generate really random passwords.
 *
 * Written by Carl S. Gutekunst.  Released into the Public Domain 95/09/28
 */
#include <stdio.h>
#include <stdlib.h>

#define PASSWD_LEN 40                   /* Number of chars in a password */

char passchars[] =
        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxuz";
char symbchars[] =
        "!$%&()*+,-./:;<=>?[]^{|}";

main()
{
    int   passIndex;
    int   symbIndex;
    char  passwd[PASSWD_LEN+1];

    srand((int) time(0));                       /* Set the seed */

    /*
     * One position will have a symbol; the rest are alphanumeric only.  This
     * corresponds to the mandates of many UNIX password checkers.
     */
    symbIndex = rand() % PASSWD_LEN;

    /*
     * Fill the password string with random characters.
     */
    for (passIndex = 0; passIndex < PASSWD_LEN; ++passIndex) {
        if (symbIndex == passIndex) {
            passwd[passIndex] = symbchars[rand() % (sizeof(symbchars) - 1)];
        }
        else {
            passwd[passIndex] = passchars[rand() % (sizeof(passchars) - 1)];
        }
    }

    /*
     * Write new passwd to stdout.
     */
    passwd[PASSWD_LEN] = '\0';
    puts(passwd);
    return 0;
}



More information about the Semibug mailing list