Hide user input

I am trying to get a script that works both in the native Windows shell and in the cygwin shell (via ssh), which requests and reads the password entered by the user. So far I have tried the following methods:

  • using Term :: ReadKey and setting ReadMode to "noecho"
    • RESULT: returns GetConsoleMode failed and exits
  • using Term :: ReadPassword :: Win32
    • RESULT: hangs and never offers an invitation or reads input
  • using IO :: Prompt
    • RESULT: returns Cannot write to terminal error and exits
  • using Term :: InKey
    • RESULT: returns an error Not implemented on MSWin32: The handle is invalid and exits

They all work in their native Windows shell (command line or command shell), but none of them work when I'm in an ssh session on the server.

Indeed, this is what interests me the most and make it work in a remote ssh session.

I get ssh through cygwin installed on a Windows server (2003 R2). I use strawberry perl, not cygwin perl (cygwin perl breaks up other perl scripts that I need to run natively on Windows and not through ssh).

My best guess is that cygwin + Windows is screwed with strawberry perl, which cannot determine what environment it is in. I am studying alternative sshd + windows solutions to explore this.

These are all the methods that I could find in my search. Does anyone else have any methods to hide the user input that they can offer?

+7
source share
3 answers

I am trying to infer environment variables (% ENV) during sessions that work, and then again during sessions that do not. I believe that when working with the IO terminal, you should carefully configure the "TERM" variable based on things like the $ ^ O variable and $ ENV {SESSIONNAME} (on Windows).

0
source

what about Term :: ReadKey ReadMode (4)? I just used this in a personal project, finding the answer here

runs on cygwin / win7, but cannot vouch for the native shell of Windows.

 use strict; use warnings; use Term::ReadKey; sub get_input { my $key = 0; my $user_input = ""; # disable control keys and start reading keys until enter key is pressed (ascii 10) ReadMode(4); while (ord($key = ReadKey(0)) != 10) { if (ord($key) == 127 || ord($key) == 8) { # backspace / del was pressed. remove last char and move cursor back one space. chop ($user_input); print "\b \b"; } elsif (ord($key) < 32) { # control characters, do nothing } else { $user_input = $user_input . $key; print "*"; } } ReadMode(0); return $user_input; } # variables my $password = ""; my $username = ""; print "\nPlease input your username: "; $username = get_input(); print "\nHi, $username\n"; print "\nPlease input your password: "; $password = get_input(); 
0
source
 use Term::ReadKey; print "Please enter your artifactory user name:"; $username = <STDIN>; chomp($username); ReadMode('noecho'); # don't echo print "Please enter your artifactory password:"; $password = <STDIN>; chomp($password); ReadMode(0); #back to normal print "\n\n"; 
0
source

All Articles