Guest User

Untitled

a guest
Jul 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ####################################################################################
  4. # Script for creating high entropy based password strings.
  5. #
  6. # Will iterate and generating high entropy password for char length and total nbr of
  7. # of passwords. If no password length provided Minimum length of characters in
  8. # password string is 8.
  9. #
  10. # Usage: sh entropy_pswd_creator.sh [nbr-passwords] [max-pswd-length]
  11. #
  12. # Exit code of 0 if successful else non zero means failed.
  13. # ####################################################################################
  14.  
  15. # global Vars
  16. PSWD_LEN=8
  17. NBR_PSWD=1
  18.  
  19. function usage {
  20. echo "Usage: $1 [nbr-passwords] [max-pswd-length]"
  21. echo "-nbr-password number of passwords to generate"
  22. echo "-max-pswd-length maxinum string length of characters in password"
  23. }
  24.  
  25. function is_nbr {
  26. # check if positive nbr
  27. local nbr=$1
  28.  
  29. if [ -z "${nbr}" ]; then
  30. echo 1
  31. fi
  32. re='^[0-9]+$'
  33. if [[ $nbr =~ $re ]] ; then
  34. echo 0
  35. else
  36. echo 1
  37. fi
  38. }
  39.  
  40. function generate_pswd {
  41. local str_len=$1
  42. if [ -z "$str_len" ]; then
  43. str_len=${MIN_LEN}
  44. fi
  45. pswd=$(LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c ${str_len} ; echo)
  46. echo "${pswd}"
  47. }
  48.  
  49. # validate input
  50. if [ "$#" -gt 2 ]; then
  51. echo "Invalid arguments passed: ${@}"
  52. usage $0
  53. exit 1
  54. fi
  55.  
  56. if [ "$#" -ge 1 ]; then
  57. rc=`is_nbr $1`
  58. [[ $rc -ne 0 ]] && echo "Invalid input NaN: ${1}" && exit 2
  59. NBR_PSWD=$1
  60. fi
  61. if [ "$#" -ge 2 ]; then
  62. rc=`is_nbr $2`
  63. [[ $rc -ne 0 ]] && echo "Invalid input NaN: ${2}" && exit 3
  64. PSWD_LEN=$2
  65. fi
  66.  
  67. #echo "nbr pass ${NBR_PSWD}"
  68. #echo "leng ${PSWD_LEN}"
  69.  
  70. for i in `seq 1 ${NBR_PSWD}`;
  71. do
  72. generate_pswd ${PSWD_LEN}
  73. done
  74.  
  75. exit 0
Add Comment
Please, Sign In to add comment