Skip to content
Simple secure password generation shell script
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Generate secure passwords

PassGen is a password generation shell script. allows the one to generate secure passwords for websites. To use, do something like this:

echo 'Some secret string hlrehcv5kn4' > ~/.master_password # Only do this once

Replace Some secret string hlrehcv5kn4 with a suitably hard to guess string, and with the site you need to log in to.

This script is for people familiar with shell scripting (or Bash, as it’s usually called these days); by being a shell script, the rules can be customized for sites with difficult password rules.

To create another password for the site, edit the file to give, say, a higher INDEX value.

Requirements to install:

  • A Posix compliant Bourne Shell compatible command line interpreter (this comes with Linux and Mac; Windows users can install Cygwin)
  • A C compiler with the name cc This compiles the underlying cryptographic program.

Dealing with website rules


The password “hlrehcv5kn4o545v” has (or had, until I posted this) a good deal more security than “Password1!” (the first has 80 bits of entropy; the largest attacks I have seen, requiring entire datacenters filled with computers, can crack 64 bits; the second has at best 28 bits of security), but many sites consider the first password insecure and the second password secure.

Making people have mixed case or punctuation in their password does not increase password security that much. However, it makes password management a pain. For the majority of websites, adding the string _Aa9 to the end of a password will allow a password to be considered “secure”; this password generator does that.

While most sites accept the underscore _ as a “punctuation” character, some do not. Southwest, for example, does not even allow a _ in a password, so has a special “for Southwest, use : instead of _ for punctuation” rule in it.

To handle site specific rules, the script will need to be edited by hand for each site with a stupid password rule which its default behavior does not cover. There is a section giving examples of how to deal with site-specific rules.

Security considerations

The master password needs to be kept secret. The master password should have enough entropy (i.e. be long enough) to be difficult to guess.

Cryptography used

The underlying C program which provides the cryptography for passwords is only 12 lines long.

#include <stdio.h> // cc -o microrg32 microrg32.c ; WORK=3 ; LEN=4 #######
#include <stdint.h> // SECRET="Something random like qhohxks5mx9el9v6ujg3"
#include <stdlib.h> // export P="$LEN:$" ## Public domain code
#define b(z) for(c=0;c<(z);c++) // ./microrg32 $WORK $LEN | head -1 | tail
uint32_t c,e[40],f[40],g=19,h=13,r,s,t=2,n[45],i,k,y,z;void m(){int c,j=0;
+1]^n[c+4];*e^=1;b(3)e[c+h]^=f[c*h]=f[c*h+h];}int main(int p,char**v){char
s>>=8;printf("%c",255&i);}c=r;if(!--z)puts("");}puts("__");return 0;}}}}}}

This is a compact implementation, suitable for printing on a coffee mug, of RadioGatún32, a secure hash function and stream cipher. For programmers who find this hard to read, a somewhat out of date explanation of how the code works is available.

The above program also has a user guide.

Some other C programs

This package includes a couple of other C programs:

  • randomLetters.c This small C program generates 32 random letters with 5 bits of entropy each, giving us a string with 160 bits of entropy. /dev/urandom support needed (MacOS, Windows + Cygwin, Linux, any other UNIX clone with /dev/urandom)
  • microrg32.c This is a standalone version of the program which uses to generate the undelying random numbers. If the program microrg32 is in one’s $PATH, the script will not need to compile its built-in version of microrg32.c to generate secure passwords.

To compile these two programs, simply type in make (the classic UNIX make program will, of course, be needed—it’s surprising how many so-called UNIX systems do not include this out of the box these days, but the package is available for pretty much every modern UNIX variant out there).

Compatibility with older versions of PassGen

Release 1.0 of PassGen, done on August 22, 2018, broke compatibility with older versions of PassGen. If older generated passwords are needed, please edit to make COST be @ instead of 3.

External links is a useful tool for seeing how secure a password really is. is a Javascript password generator using a dictionary of 2048 words four letters or shorter.

You can’t perform that action at this time.