[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

mask gets_chomp ?

Rebhan, Gilbert

3/5/2007 1:16:00 PM


Hi,

i have a script that uses a password as input.

The password is provided via gets_chomp
in the shell.

Is there a way to mask the password with *
or do i have to write a gui for that ?


Regards, Gilbert



2 Answers

Robert Klemme

3/5/2007 1:51:00 PM

0

On 05.03.2007 14:15, Rebhan, Gilbert wrote:
> Hi,
>
> i have a script that uses a password as input.
>
> The password is provided via gets_chomp
> in the shell.
>
> Is there a way to mask the password with *
> or do i have to write a gui for that ?

Maybe you can do that via curses. Other than that, you could use "stty
-echo" before and "stty echo" after the password input:

14:50:07 [~]: ruby -e 'system("stty", "-echo")
> puts "enter!"
> pass=gets.chomp
> puts "You entered #{"*" * pass.size}"
> system("stty", "echo")'
enter!
You entered ******
14:50:56 [~]:

Kind regards

robert

Xavier Noria

3/5/2007 2:17:00 PM

0

On Mar 5, 2007, at 2:15 PM, Rebhan, Gilbert wrote:

> i have a script that uses a password as input.
>
> The password is provided via gets_chomp
> in the shell.
>
> Is there a way to mask the password with *
> or do i have to write a gui for that ?

Just in case, are you aware of HighLine's ask mehod?

require 'rubygems'
require 'highline/import'

pass = ask("Password: ") {|q| q.echo = false}

-- fxn