|
|
|
|
|
by slowbdotro
1529 days ago
|
|
Not OP, but I prefer memorable passwords, thus, correct-battery-horse-staple style passwords in bash: (Install cracklib, or any dict file) #!/bin/bash
pickaword() {
WORDFREQFILE=/usr/share/dict/cracklib-small;
WORDLENGTH=$1;
awk -v wordlength="$WORDLENGTH" 'length($1) == wordlength {print $1}' "$WORDFREQFILE"|shuf|head -n 1;
}
[[ ! -z $1 ]] && numWords=$1 || numWords=4
separator="-"
count=0
currentWord=""
while [[ $count -lt $numWords ]]; do
[[ $count != 0 ]] && echo -n $separator
num=$((3 + RANDOM % 10))
word=$(pickaword $num)
echo -n "$word"
count=$(($count + 1));
done
echo ""
Edit: code formatting is hard. Source is: https://gitea.slowb.ro/ticoombs/dotfiles/src/branch/main/bin... |
|
Modulo operations like these are another thing to avoid. To get equal chances for each word, the simplest thing to do is e.g.
(Adjust if your list length is greater than 255×256+256, of course.)Further, I see that cracklib-small is 52k words. That's not good or bad, but it makes the default 4-word phrase 52e3⁴ ~ 63 bits of entropy, which isn't terrible but in my opinion on the short side as a default. It will be perfectly fine if you only ever want to defend against online attacks, but in some cases (think disk encryption or password manager) offline cracking should be kept in mind and for the rest you should usually use a password manager anyhow (so then memorability doesn't matter).
Or perhaps more succinctly: please don't roll your own crypto.
I understand that this is of course very unlikely to be abused if it's just for yourself and nobody knows of this weakness in your credentials (security through obscurity works... until it doesn't), but one day someone will use this as inspiration or it will spread somehow, say through an HN comment... just use good password generators or at least keep insecure ones secret.
Btw: many standard Debian(-based) installations have /usr/share/dict/words available so you don't need an extra install; I haven't seen cracklib used before but that might just be me.