quickpass 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. #
  3. # Quick way to generate a random password for online systems
  4. #
  5. # Usage: randompass -l [LENGTH] -n [QUANTITY], where:
  6. # length - the desired length of the password
  7. # quantity - the number of passwords to be generated (default: 1)
  8. #
  9. # Copyright (C) 2016 - kzimmermann <https://quitter.se/kzimmermann>
  10. #
  11. # This program is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. # Create a single password by default:
  25. HOW_MANY=1
  26. # Some online services put a cap on how long a password can be. We default it
  27. # to 32 characters, but you can change it accordingly. If you estipulate a
  28. # number as an argument to this program, this value is overriden
  29. # It's not recommended to use a password that's shorter than 14 characters!
  30. LENGTH=32
  31. # Get command-line options:
  32. while [[ -n "$1" ]]
  33. do
  34. case "$1" in
  35. "-h" | "--help" )
  36. cat <<EOF
  37. Quick way to generate a random throwaway password for online systems
  38. Usage: $(basename $0) -l [LENGTH] -n [QUANTITY], where:
  39. length - the desired length of the password (default: $LENGTH)
  40. quantity - the number of passwords to be generated (default: $HOW_MANY)
  41. EOF
  42. exit 0
  43. ;;
  44. "-l" | "--length" )
  45. shift
  46. LENGTH="$1"
  47. ;;
  48. "-n" | "--number" )
  49. shift
  50. HOW_MANY="$1"
  51. ;;
  52. * )
  53. echo "Error: unrecognized option '$1'"
  54. exit 1
  55. ;;
  56. esac
  57. # call next round
  58. shift
  59. done
  60. for ((i=0; i < $HOW_MANY; i++))
  61. do
  62. seed="$(dd if=/dev/urandom bs=512 count=1 2> /dev/null | tr -dc [:graph:])"
  63. index=${RANDOM:2:2}
  64. # I need to do this to avoid things like 09, 04, etc
  65. [[ ${index:0:1} == "0" ]] && index=${index:1:1}
  66. password=${seed:$index:$LENGTH}
  67. echo $password | xsel -ib
  68. done
  69. echo "Your password was copied to your clipboard."