[Semibug] Generate random passwords?
Jonathan Drews
jondrews at fastmail.com
Fri Jul 16 18:01:14 EDT 2021
On Fri, Jul 16, 2021 at 02:57:29PM -0400, Mike Wayne wrote:
> 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:
>
Thanks Mike:
Works like a charm!
cleetus:6$ ./a.out
c1kg&4oprueTLQatY9vt5sG66tcmcG3bFj0xwJlM
cleetus:7$ ./a.out
X6CjMwTtiivBL6IJ4C9PzVz6N7qCK=E0uALxFEBd
>
> /*
> * 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;
> }
>
> _______________________________________________
> Semibug mailing list
> Semibug at lists.nycbug.org
> http://lists.nycbug.org:8080/mailman/listinfo/semibug
More information about the Semibug
mailing list