Guest User

Untitled

a guest
Mar 30th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Generates bcrypt password
  4. # USAGE
  5. #
  6. # $ ./genpass.sh
  7. # Password:
  8. #
  9. # or (also sets password for user in .credentials.json)
  10. #
  11. # $ ./genpass.sh johndoe
  12. # Password:
  13. #
  14. # OPTIONS
  15. # --verbose, -v
  16. # Print hash to console.
  17. #
  18.  
  19. require 'io/console'
  20. require 'bcrypt'
  21. require 'json'
  22.  
  23. input = [(print 'Password: '), STDIN.noecho(&:gets).chomp][1]
  24. hash = BCrypt::Password.create(input)
  25.  
  26. is_verbose = ARGV.any? { |v| v == '--verbose' || v == '-v' }
  27. if is_verbose
  28. puts
  29. puts hash
  30. end
  31.  
  32. if ARGV.length > 0
  33. credentialsPath = '.credentials.json'
  34. username = ARGV[0]
  35. file = File.read(credentialsPath)
  36. data = JSON.parse(file)
  37. data[username] = hash
  38. File.write(credentialsPath, data.to_json)
  39. end
Add Comment
Please, Sign In to add comment