passgen 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. #
  3. # passgen - create strong passwords from easy-to-remember strings
  4. #
  5. # This is a fork of the Password generator from the one in JXSelf's post:
  6. #
  7. # https://jxself.org/password-generator.shtml
  8. #
  9. # In his original proposal, Jonathan suggests taking a hash of a relatively
  10. # weak password composed of a password seed (called there a "salt") combined
  11. # with a service-specific identifier (called a "string") and encoding it with
  12. # base64 to produce a 32 character strong-looking password.
  13. #
  14. # However, it ocurred to me that perhaps these passwords may be easy to reverse
  15. # in case it becomes known that you indeed generate your passwords using this
  16. # method. All the attacker has to do is realize that the password looks like a
  17. # base64-encoded string (easy to infer from the pattern of the string).
  18. #
  19. # For example, suppose you use the salt "banana" and the string "example.com"
  20. # to get the password YmFmNzc1MjQ1MWJlMWI2Y2IyNGQyNjJk. Decoding that, we get:
  21. # baf7752451be1b6cb24d262d, a slice of the original hash. That information
  22. # could be used to figure out parts of the hashed string, most importantly the
  23. # common salt used accross all passwords...
  24. #
  25. # My modifications include the insertion of additional methods for making the
  26. # reversibility harder, and the usage of more non-alphanumeric characters
  27. # through the usage of tr.
  28. #
  29. # --------
  30. # Short history:
  31. # 0.1-ALPHA - first usable release
  32. # --------
  33. #
  34. # Copyright (C) 2016 - kzimmermann <https://quitter.se/kzimmermann>
  35. #
  36. # This program is free software: you can redistribute it and/or modify
  37. # it under the terms of the GNU General Public License as published by
  38. # the Free Software Foundation, either version 3 of the License, or
  39. # (at your option) any later version.
  40. #
  41. # This program is distributed in the hope that it will be useful,
  42. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. # GNU General Public License for more details.
  45. #
  46. # You should have received a copy of the GNU General Public License
  47. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  48. #
  49. while [ true ];
  50. do
  51. printf "Enter your salt: "
  52. read -s SALT
  53. printf "\n"
  54. printf "Confirm: "
  55. read -s SALT_CONFIRM
  56. echo -en "\n"
  57. if [ "$SALT" == "$SALT_CONFIRM" ]; then
  58. break
  59. fi
  60. echo "Salts don't match. Please try again."
  61. done
  62. if [[ -z "$1" ]]
  63. then
  64. printf "Enter your string: "
  65. read STRING
  66. else
  67. STRING="$1"
  68. fi
  69. HASH=$(printf "$SALT$STRING" | sha512sum | cut -d " " -f 1)
  70. HASH2=$(printf "$STRING$SALT" | sha512sum | cut -d " " -f 1)
  71. REV=$(printf $HASH | rev)
  72. # Yes, enough readable characters come out of this mess.
  73. PASSWORD=$(
  74. printf "$REV$HASH$HASH2" |
  75. base64 -d 2> /dev/null |
  76. tr -dc [:graph:]
  77. )
  78. echo ${PASSWORD:0:32}
  79. echo "Copy and press enter to finish"
  80. read
  81. # clear screen safely so to make difficult scrolling back to read it.
  82. for ((i=0; i < 500; i++))
  83. do
  84. printf "\n\n\n"
  85. done
  86. clear