Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #Author: Dylan Ivan Hubbard
- #Name: PasswordGenerator
- ##########################################################################################################
- GENERROR1 (){
- # Creating our error function which will inform the user on the correct script usage.
- # tpuf setaf will display our guidelines in a distinctive color, allowing the
- # user to recognize it properly.
- ###########################################################################################################
- tput setaf 3
- echo -e "Password is incorrect, guidelines provided: \n"
- echo -e " MUST contain at least 1 digit
- MUST contain at least 1 uppercase character
- MUST contain at least 1 lowercase character
- MUST contain ONE special character
- MUST be a minimum of 8 characters long
- Have a g'day, mate. "
- tput setaf 7
- exit 0
- }
- ##########################################################################################################################################
- #PASSWORD FUNCTION
- PASSWORDGEN (){
- tput setaf 2
- echo -n "Here is your password, eh: "
- pick() { echo ${1:RANDOM%${#1}:1}; }
- {
- pick '@#$%&*+-='
- pick '0123456789'
- pick 'abcdefghijklmnopqrstuvwxyz'
- pick 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
- do
- pick '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
- done
- } | sort -R | tr -d '\n'
- echo ""
- tput setaf 7
- exit 1
- }
- ##################################################################################################################################
- # Assuming the user enters a password and not a parameter such as "-h", we will check the length of the password entered,
- # It cannot be less than 8 characters and not more than 16.
- if [ $# -eq 1 ]
- then
- USERPASSWORD=$(echo -n $1 | wc -c)
- fi
- if [[ $USERPASSWORD -gt 16 || $USERPASSWORD -lt 8 ]]
- then
- echo "Error - Invalid Length - $1"
- error=1
- fi
- ###################################################################################################################################
- # Here we will read what the user's input is, we will check if the first
- # positional parameter contains any characters, if not, we will generate a
- # password for the user according to our guidelines, but if -h is our
- # parameter, our script will list the guidelines in order, to use the
- # script accordingly.
- if [ "$1" = "" ]
- then
- PASSWORDGEN
- fi
- if [ "$1" = "-h" ]
- then
- GENERROR1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement