passphraser 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. #
  3. # passphraser: turn a passphrase (even a bad one like a verse from a well-known
  4. # song) into a good password.
  5. #
  6. # WIP, inspired by miscellaneous posts in diaspora and gnusocial. No warranty
  7. # of usage, not even that will work in your system.
  8. #
  9. # A few remarks:
  10. #
  11. # - This program makes a sha224 hash as the final password. Assuming sha224
  12. # doesn't break (i.e. nobody finds collisions, etc), and the service you
  13. # use has a decent char limit for passwords, this should be OK. If your
  14. # character limit is lower, then you should probably try a password manager
  15. # instead.
  16. # - Passwords here are deterministic, and many-to-one due to the process of
  17. # simplification used. IMO, this is a trade-off: less chance for typos but
  18. # a slightly higher chance of collision. You can change this easily below.
  19. # - Ideal usage: use the password you generated here to unlock your password
  20. # manager database. And then use that to generate your other 2000 passwords.
  21. #
  22. # Copyright 2018 - kzimmermann <https://notabug.org/kzimmermann>
  23. #
  24. # This program is free software licensed under the terms and conditions of the
  25. # GNU GPL v3. See LICENCE for more information.
  26. #
  27. printf "Enter a phrase you know well: "
  28. read phrase
  29. if [[ -z $(which xsel) ]]
  30. then
  31. printf "$phrase" |
  32. tr " " "\n" |
  33. sort |
  34. tr "\n" "m" | # "m" is arbitrary.
  35. tr [A-Z] [a-z] |
  36. tr -dc [:alnum:] |
  37. base64 |
  38. sha224sum |
  39. cut -d " " -f 1
  40. echo "This is your suggested password."
  41. else
  42. printf "$phrase" |
  43. tr " " "\n" |
  44. sort |
  45. tr "\n" "m" | # "m" is arbitrary.
  46. tr [A-Z] [a-z] |
  47. tr -dc [:alnum:] |
  48. base64 |
  49. sha224sum |
  50. cut -d " " -f 1 |
  51. xsel -ib
  52. echo "Password copied to clipboard."
  53. fi