A password generator with defaults and some shorthands that I like
Mostly written to un-rust my C++ (heh...), but I do use this whenever I need a password
usage:
genpasswd
genpasswd PASSWD_LENGTH
genpasswd [-n PASSWD_LENGTH] [-r CHARACTER_SET] [-c COUNT] [-p|-s]
options:
-n N length of password to generate
-c C number of passwords to generate
-r R character set to remove from allowed characters
-p shorthand for -n 4 -r lower -r upper -r sym
to generate a string of random numbers of length 4
meant to be used for bank pins
-s shorthand for -n 16 -r sym
meant for websites which have strict limits on passwords
character sets:
lowercase : l, lower, lowercase
uppercase : u, upper, uppercase
numbers : n, num, number, numbers
symbols : s, sym, symbol, symbols
examples:
genpasswd 40 : password of length 40
genpasswd -n 30 -rsym : password of length 30 without symbols
genpasswd -p : generate a bank pin
Type genpasswd -h for help
git clone https://github.com/purarue/genpasswd
cd genpasswd
make
make install
Some of the defaults can be modified by changing environment variables.
GENPASSWD_LENGTH
: default password length, defaults to 20GENPASSWD_SIMPLE_LENGTH
: defaults simple (-s) password length, defaults to 16GENPASSWD_PIN_LENGTH
: default pin (-p) password length, defaults to 4GENPASSWD_COUNT
: default password count (-c), defaults to 1
This adheres to getopts, so you can put this in your zsh config:
# if not already present, run compinit
autoload -Uz compinit && compinit
compdef _gnu_generic genpasswd
... which generates completion like:
genpasswd -
-c -- number of passwords to generate
-n -- length of password to generate
-p -- shorthand for -n 4 -r lower -r upper -r sym
-r -- character set to remove from allowed characters
-s -- shorthand for -n 16 -r sym
I wrap this in a bash script here that copies the password to my clipboard. That looks something like:
#!/usr/bin/env bash
pw=$(genpasswd "$@" | head -n 1 | tr -d "\n")
echo -e "$pw"
# copy to clipboard
echo -en "$pw" | xclip -selection clipboard
This uses xclip, but if you don't have that you could use pbcopy/xsel