#!/bin/bash
# Beforehand, do these things;
# sudo apt install wamerican-large
# egrep '^[a-z]{3,5}$' /usr/share/dict/words > ~/bin/words.txt
# This gives a list of about 23,000 all lowercase words.
# or, if you want things to all be the same length, use this;
# egrep '^[a-z]{4}$' /usr/share/dict/words > ~/bin/words.txt
Words=~/bin/words.txt
# Minimum length of Pass
Len=15
# If a number was passed as an argument, set length to it
[[ ${1} == ?(-)+([0-9]) ]] && Len=${1}
Count=1
# If two numbers are passed in, give a list of that many passphrases
[[ ${2} == ?(-)+([0-9]) ]] && Count=${2}
True=1
False=0
Sym='!@#$%^&*-_'
Num='1234567890'
SymCnt=${#Sym}
NumCnt=${#Num}
Loop=1
while [ ${Loop} -le ${Count} ]
do
TorF=$(( RANDOM % 2 ))
First=$(shuf -n 1 ${Words})
String=${First^}
while [ ${#String} -le ${Len} ]
do
if [ ${TorF} -eq ${True} ]; then
TorF=${False}
String+="${Sym:$(($RANDOM%${SymCnt})):1}"
else
TorF=${True}
String+="${Num:$(($RANDOM%${NumCnt})):1}"
fi
This=$(shuf -n 1 ${Words})
String+=${This^}
done
echo ${String}
((Loop++))
done
This gives these results;
steve@clug:~$ GenPass ## Default, a password with 15 or more characters.
Raced_Cavel5Slews
steve@clug:~$ GenPass 24 ## With an argument of 24, a password with 24 or more characters.
Baals*Ikons1Glump%Eel7Hause
steve@clug:~$ GenPass 15 20 ## With two arguments, a list of passwords with 15 or more characters.
Gled$Isle9Fuji#Punts
Doxy&Darr8Ours!Pash
Gaine6Ferv*Intl0Olam
Luxe!Tikor4Messe
Tungo8Lucky^God4Grav
Rejig0Param!Rebel
Tunas0Crow$Sqq8Brail
Hemin3Sics@Abb5Haddo
Cork1Theft!Tests
Gater%Drate6Ebbed
Emery&Snoop9Condo
Zap7Ack@Nosey8Tuxes
Saxe9Zho*Moit5Yechs
Hom5Kobs!Stow0Tahin
Duke@Nanes8Wawls
Marc_Fiche0Reap-Loads
Chime^Maynt4Teer
Molpe3Mna&Foder6Ways
Siva8Oshea-Ter0Grab
Footy7Takyr!Alden