Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ####################################################################################
- # Script for creating high entropy based password strings.
- #
- # Will iterate and generating high entropy password for char length and total nbr of
- # of passwords. If no password length provided Minimum length of characters in
- # password string is 8.
- #
- # Usage: sh entropy_pswd_creator.sh [nbr-passwords] [max-pswd-length]
- #
- # Exit code of 0 if successful else non zero means failed.
- # ####################################################################################
- # global Vars
- PSWD_LEN=8
- NBR_PSWD=1
- function usage {
- echo "Usage: $1 [nbr-passwords] [max-pswd-length]"
- echo "-nbr-password number of passwords to generate"
- echo "-max-pswd-length maxinum string length of characters in password"
- }
- function is_nbr {
- # check if positive nbr
- local nbr=$1
- if [ -z "${nbr}" ]; then
- echo 1
- fi
- re='^[0-9]+$'
- if [[ $nbr =~ $re ]] ; then
- echo 0
- else
- echo 1
- fi
- }
- function generate_pswd {
- local str_len=$1
- if [ -z "$str_len" ]; then
- str_len=${MIN_LEN}
- fi
- pswd=$(LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c ${str_len} ; echo)
- echo "${pswd}"
- }
- # validate input
- if [ "$#" -gt 2 ]; then
- echo "Invalid arguments passed: ${@}"
- usage $0
- exit 1
- fi
- if [ "$#" -ge 1 ]; then
- rc=`is_nbr $1`
- [[ $rc -ne 0 ]] && echo "Invalid input NaN: ${1}" && exit 2
- NBR_PSWD=$1
- fi
- if [ "$#" -ge 2 ]; then
- rc=`is_nbr $2`
- [[ $rc -ne 0 ]] && echo "Invalid input NaN: ${2}" && exit 3
- PSWD_LEN=$2
- fi
- #echo "nbr pass ${NBR_PSWD}"
- #echo "leng ${PSWD_LEN}"
- for i in `seq 1 ${NBR_PSWD}`;
- do
- generate_pswd ${PSWD_LEN}
- done
- exit 0
Add Comment
Please, Sign In to add comment