How to get string from console without echo? I need it for password reading.
Szymon Drejewicz
How to get string from console without echo? I need it for password reading.
Szymon Drejewicz
EHLO
How to get string from console without echo? I need it for password
reading.
Use termios available at
http://raa.ruby-lang.org/list.rhtml?name=ruby-termios
Sample usage (note that the input routine has the potential of
showing a strange behavior: When a star is shown for every password
character, the stars do not fit into one line and you use backspace
the stars in the first line will not vanish even if the corresponding
characters are deleted):
require ‘termios’ # Use termios for non-echoing input of password
BS = 8
LF = 10
DEL = 127
#==============================================================================
#==============================================================================
def read_pass(stars)
pass = ‘’
$stdin.extend Termios
oldt = $stdin.tcgetattr
newt = oldt.dup
newt.lflag &= ~(Termios::ECHO | Termios::ICANON)
$stdin.tcsetattr(Termios::TCSANOW, newt)
loop {
c = $stdin.getc
break if c == LF
if (c == BS or c == DEL) and (not pass.empty?)
pass.chop!
print “#{BS.chr} #{BS.chr}” if stars
else
pass <<= c.chr
print ‘*’ if stars
end
}
$stdin.tcsetattr(Termios::TCSANOW, oldt)
print “\n”
return pass
end
HTH
.---------------------. .------…—…-----…—…-----.
http://jupp.tux.nu/ | | jupp || @ || gmx || . || net |
---------------------'
------‘---'
-----’---'
-----’
Thanks for the demonstration, Josef. I often wondered myself how to
do it. Your program is archived at
http://www.rubygarden.org/ruby?PasswordWithoutEcho
Gavin
On Wednesday, March 12, 2003, 2:08:57 AM, Josef wrote:
EHLO
- On 2003-03-11 13:57
- Szymon Drejewicz drejewic@wsisiz.edu.pl wrote:
How to get string from console without echo? I need it for password
reading.
Use termios available at …