OpenBSD Shell Password Generator
This is the code I found online.
genpass.sh
#bin/sh
# copy to /usr/local/bin# usage: genpass [length]
LENGTH=12if [ 0 -lt $(($1)) ]; then LENGTH=$1fi
# extract enough bytes from the random number generatordd bs=$((80*$LENGTH)) count=1 if=/dev/random 2>/dev/null | LC_CTYPE=C tr -cd 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz' | cut -b 1-$LENGTHAlternatively, we can use AI generated code:
genpass_strong.sh
#!/bin/ksh
# Function to generate a secure random passwordgenerate_password() { local length=$1 local charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?~"
while [ ${#password} -lt $length ]; do rand_char=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | LC_CTYPE=C tr -dc "$charset") password="${password}${rand_char}" done
echo "$password"}
# Generate a password with a length of 12 characterspassword=$(generate_password 12)
echo "Generated password: $password"