Perl on Win32: any possibility to emule read_password
Hi folks, the question is very simple: the function read_password does not work on Win 32 platforms. I have been searching for a solution everywhere i knew about, without success. how could I achieve my goal, that is exactly to input a password without curious people to see what is written ? Thanks in advance Eric ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl on Win32: any possibility to emule read_password
ericv wrote: Hi folks, the question is very simple: the function read_password does not work on Win 32 platforms. I have been searching for a solution everywhere i knew about, without success. how could I achieve my goal, that is exactly to input a password without curious people to see what is written ? Guess what Eric, I have no idea what you're talking about. What's read_password ? Part of some of your code, maybe a function in a Perl module, some C code maybe ? Please be a little more explcit since there are ways to accept input without echoing, we just need to know what you're talking about - web page, commandline, GUI window ? -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Perl on Win32: any possibility to emule read_password
ok Bill, I am talk about the function read_password which is part of the Term module. It apparently works in all other platforms ( unix, etc...) but is know not to work on Win32 ( and i confirm that!) I am working on a command line script, and need to input a password from the console, and obviously i would avoid to show it explicitly. Any ideas ? Thanks -Original Message- From: $Bill Luebkert [mailto:[EMAIL PROTECTED] Sent: Wed 5/25/2005 2:09 PM To: ericv Cc: perl-win32-users@listserv.ActiveState.com Subject: Re: Perl on Win32: any possibility to emule read_password ericv wrote: Hi folks, the question is very simple: the function read_password does not work on Win 32 platforms. I have been searching for a solution everywhere i knew about, without success. how could I achieve my goal, that is exactly to input a password without curious people to see what is written ? Guess what Eric, I have no idea what you're talking about. What's read_password ? Part of some of your code, maybe a function in a Perl module, some C code maybe ? Please be a little more explcit since there are ways to accept input without echoing, we just need to know what you're talking about - web page, commandline, GUI window ? -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl on Win32: any possibility to emule read_password
ericv wrote: ok Bill, I am talk about the function read_password which is part of the Term module. It apparently works in all other platforms ( unix, etc...) but is know not to work on Win32 ( and i confirm that!) I am working on a command line script, and need to input a password from the console, and obviously i would avoid to show it explicitly. Any ideas ? Yes - don't use read_password if it doesn't work. I don't know about the 'Term' module, but you can use Term::ReadKey module: use strict; use warnings; use Term::ReadKey; END { ReadMode ('restore'); } # just in case $| = 1; # unbuffer stdout my $pwd = ''; # echoes * for each char and allows correction binmode STDIN; print Password: ; ReadMode ('cbreak'); while (defined (my $ch = ReadKey ())) { last if $ch eq \x0a or $ch eq \x0d; if ($ch eq \x08) {# backspace print \b \b if $pwd; # back up 1 chop $pwd; next; } if ($ch eq \x15) {# ^U print \b \b x length $pwd;# back 1 for each char $pwd = ''; next; } $pwd .= $ch; print '*'; } ReadMode ('restore'); print \n; print Password entered was $pwd\n; # This will also work, but it's not as functional and doesn't echo *'s: # print Password: ; # ReadMode ('noecho'); # my $pwd = ReadLine (); # chomp $pwd; # ReadMode ('restore'); __END__ You can also use a less portable Win32 solution (haven't verified lately) : use strict; use warnings; use Win32::Console; $| = 1; # unbuffer stdout my $debug = 0; my $key = ''; my $passwd = ''; my $prompt = Type password followed by ENTER: ; my $prompt2 = try again: ; my $IN = new Win32::Console (STD_INPUT_HANDLE) or die $!; print $prompt; $IN-Flush (); # optionally flush input while (1) { my @e = $IN-Input(); print Event='@e'\n if $debug; next if ($e[0] != 1 or $e[1] != 0); # not keybd key up my $key = chr ($e[5]); print key=$key '$e[5]'\n if $debug; if ($key =~ /[\r\n]/) { # EOL if (length $passwd 0) { print \n; last; } } elsif ($e[5] == 8 and ($e[6] == 8 or $e[6] == 0)) { # BS or DEL $passwd =~ s/^(.*).$/$1/; print \b \b; print 1 passwd=$passwd , length $passwd, \n if $debug; } elsif ($e[6] == 8 and $e[5] == 21) { # ^U $passwd = ''; print 2 passwd=$passwd , length $passwd, \n if $debug; } elsif ($e[6] == 8 and ($e[5] == 4 or $e[5] == 26)) { # ^D or ^Z last; } elsif ($e[6] == 0 or $e[6] == 16) { # regular key next if $e[5] == 0; $passwd .= $key; print 3 passwd=$passwd , length $passwd, if $debug; print *; print \n if $debug; } else { print ? passwd=$passwd , length $passwd, \n if $debug; print Illegal key\n; } } print passwd=$passwd\n if $debug; $IN-Flush (); #$IN-Free (); # don't free or you lose STDOUT #undef $IN; __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl on Win32: any possibility to emule read_password
Hi Eric, ericv wrote: ok Bill, I am talk about the function read_password which is part of the Term module. It apparently works in all other platforms ( unix, etc...) but is know not to work on Win32 ( and i confirm that!) I am working on a command line script, and need to input a password from the console, and obviously i would avoid to show it explicitly. Any ideas ? TermReadkey works on Win32. Not as well as on Linux/Unix, but it works. Not pretty but it works too :-D [EMAIL PROTECTED] scripts $ cat password.pl #!/usr/bin/perl use strict; use warnings; use Term::ReadKey; my $name; my $password; print Your name?: ; $name = GetInput(); print Your password: ; $password = GetInput(passwd); print \n; sub GetInput { my $token; $_ = shift; ReadMode('noecho') if defined $_ ( $_ eq passwd ); while ( not defined ( $token = ReadLine(0) ) ) { # No key pressed yet } ReadMode('normal') if defined $_ ( $_ eq passwd ); chomp $token; return $token } Hth Alex Thanks -Original Message- From: $Bill Luebkert [mailto:[EMAIL PROTECTED] Sent: Wed 5/25/2005 2:09 PM To: ericv Cc: perl-win32-users@listserv.ActiveState.com Subject: Re: Perl on Win32: any possibility to emule read_password ericv wrote: Hi folks, the question is very simple: the function read_password does not work on Win 32 platforms. I have been searching for a solution everywhere i knew about, without success. how could I achieve my goal, that is exactly to input a password without curious people to see what is written ? Guess what Eric, I have no idea what you're talking about. What's read_password ? Part of some of your code, maybe a function in a Perl module, some C code maybe ? Please be a little more explcit since there are ways to accept input without echoing, we just need to know what you're talking about - web page, commandline, GUI window ? -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs -- Alexander Apprichscience + computing ag IT-Services Hagellocher Weg 71-75 phone +49(0)7071 9457-291 D-72070 Tuebingen, Germany fax +49(0)7071 9457-211 www.science-computing.de s+c certificates via http://www.science-computing.de/cacert.crt ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs