utils/genpass.sh
Irrlicht d504fdfc4b
[genpass] New script to generate a password
Thank to Codimp for the base command
2026-02-21 22:45:40 +01:00

31 lines
667 B
Bash
Executable file

#!/bin/bash
print_help() {
echo "Usage: genpass NUMBER"
echo "Generate a NUMBER long password using the characters _, A-Z, a-z, 0-9 exclusively."
echo " -h, --help Display this help message and exit."
}
pwd_length=
while [ $# -gt 0 ]
do
case $1 in
-h|--help)
shift
print_help
exit 0
;;
*)
pwd_length=$1
shift
;;
esac
done
regex_number='^[0-9]+$'
if ! [[ $pwd_length =~ $regex_number ]] ; then
echo "error: '$pwd_length' is not a valid number" >&2; exit 1
fi
cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c ${1:-$pwd_length}