Last active
August 29, 2015 14:12
-
-
Save drhuffman12/a8c0fbc1cfb4f9864792 to your computer and use it in GitHub Desktop.
Get password from console via Java and JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GIST: "pw_from_console.rb" under "https://gist.github.com/drhuffman12" | |
# If you're dealing with a Java character array (such as password characters that you read from the console), you can convert it to a JRuby string with the following Ruby code: | |
jconsole = Java::java.lang.System.console() | |
password = jconsole.readPassword() | |
ruby_string = '' | |
password.to_a.each {|c| ruby_string << c.chr} | |
# .. do something with 'password' variable .. | |
puts "password_chars: #{password_chars.inspect}" | |
puts "password_string: #{password_string}" | |
# See also "http://stackoverflow.com/a/27628738/4390019", and "http://stackoverflow.com/a/27628756/4390019" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment