# Mask gets\_chomp?

**URL:** <https://www.ruby-forum.com/t/mask-gets-chomp/87711>\
**Category:** Ruby\
**Created:** [March 5, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/mask-gets-chomp/87711 "2007-03-05T14:16:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [March 5, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/mask-gets-chomp/87711/1 "2007-03-05T14:16:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [March 5, 2007, 2:55pm UTC](https://www.ruby-forum.com/t/mask-gets-chomp/87711/2 "2007-03-05T14:55:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [March 5, 2007, 3:06pm UTC](https://www.ruby-forum.com/t/mask-gets-chomp/87711/3 "2007-03-05T15:06:42Z")

</div>

Hi,

/\*  
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 [~]:  
> \*/

How to adopt that for =

cvsrepos=%w[…]  
cvspass=gets.chomp

cvsrepos.each {|x|  
puts “Login CVS Repository \>\> #{x} …”  
IO.popen("#{CVSEXE} -d  
:pserver:#{ENV[“USERNAME”]}:#{cvspass}@cvshostd:/cvsrepos/#{x} login")  
}  
puts “Login successful !!”

the password is readable in the cmd shell

Regards, Gilbert

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [March 5, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/mask-gets-chomp/87711/4 "2007-03-05T15:17:43Z")

</div>

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
