Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Generates bcrypt password
- # USAGE
- #
- # $ ./genpass.sh
- # Password:
- #
- # or (also sets password for user in .credentials.json)
- #
- # $ ./genpass.sh johndoe
- # Password:
- #
- # OPTIONS
- # --verbose, -v
- # Print hash to console.
- #
- require 'io/console'
- require 'bcrypt'
- require 'json'
- input = [(print 'Password: '), STDIN.noecho(&:gets).chomp][1]
- hash = BCrypt::Password.create(input)
- is_verbose = ARGV.any? { |v| v == '--verbose' || v == '-v' }
- if is_verbose
- puts
- puts hash
- end
- if ARGV.length > 0
- credentialsPath = '.credentials.json'
- username = ARGV[0]
- file = File.read(credentialsPath)
- data = JSON.parse(file)
- data[username] = hash
- File.write(credentialsPath, data.to_json)
- end
Add Comment
Please, Sign In to add comment