Advertisement
Guest User

tt.sh

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.14 KB | None | 0 0
  1. #! /bin/bash
  2. #Author: Dylan Ivan Hubbard
  3. #Name: PasswordGenerator
  4.  
  5.  
  6. ##########################################################################################################
  7.  
  8.  
  9.                 GENERROR1 (){
  10.  
  11.  
  12. # Creating our error function which will inform the user on the correct script usage.
  13. # tpuf setaf will display our guidelines in a distinctive color, allowing the
  14. # user to recognize it properly.
  15.  
  16. ###########################################################################################################
  17.  
  18.     tput setaf 3
  19.  
  20.         echo -e "Password is incorrect, guidelines provided: \n"
  21.  
  22.    echo -e " MUST contain at least 1 digit
  23.         MUST contain at least 1 uppercase character
  24.         MUST contain at least 1 lowercase character
  25.         MUST contain ONE special character
  26.         MUST be a minimum of 8 characters long
  27.  
  28.            Have a g'day, mate. "
  29.    
  30.    
  31.     tput setaf 7
  32.  
  33. exit 0
  34.  
  35. }
  36.  
  37. ##########################################################################################################################################
  38. #PASSWORD FUNCTION
  39.  
  40.  
  41.  
  42.                 PASSWORDGEN (){
  43.  
  44.     tput setaf 2
  45.  
  46.  
  47.    echo -n "Here is your password, eh: "
  48.  
  49.  
  50.     pick() { echo ${1:RANDOM%${#1}:1}; }
  51.  
  52.  
  53. {
  54.  
  55.         pick '@#$%&*+-='
  56.          pick '0123456789'
  57.                 pick 'abcdefghijklmnopqrstuvwxyz'
  58.                     pick 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  59.  
  60.            
  61.  
  62.         for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
  63.        
  64.  
  65. do
  66.    
  67.  
  68.  
  69. pick '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  70.  
  71.         done
  72.  
  73.  
  74. } | sort -R | tr -d '\n'
  75.  
  76.         echo ""
  77.  
  78. tput setaf 7
  79.  
  80.  
  81.                  exit 1
  82.  
  83.          }
  84.  
  85.  
  86.  
  87.  
  88. ###################################################################################################################################
  89.  
  90.  
  91. # Here we will read what the user's input is, we will check if the first
  92. # positional parameter contains any characters, if not, we will generate a
  93. # password for the user according to our guidelines, but if -h is our
  94. # parameter, our script will list the guidelines in order, to use the
  95. # script accordingly.
  96.  
  97.             if [ "$1" = "" ]
  98.  
  99.         then
  100.  
  101.             PASSWORDGEN
  102.  
  103. fi
  104.  
  105.  
  106.  
  107.  
  108.             if [ "$1" = "-h" ]
  109.  
  110.  
  111.         then
  112.  
  113.             GENERROR1
  114.  
  115. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement