Method: Password.get

Defined in:
lib/password.rb

.get(message = "Password: ") ⇒ Object

Get a password from STDIN, using buffered line input and displaying message as the prompt. No output will appear while the password is being typed. Hitting [Enter] completes password entry. If STDIN is not connected to a tty, no prompt will be displayed.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/password.rb', line 185

def Password.get(message="Password: ")
  begin
    if $stdin.tty?
	Password.echo false
	print message if message
    end

    pw = Password.new( $stdin.gets || "" )
    pw.chomp!

  ensure
    if $stdin.tty?
	Password.echo true
	print "\n"
    end
  end
end