Loading ...
Sorry, an error occurred while loading the content.

Re: How to enter a password without echo on DOS?

Expand Messages
  • Damien Carbery
    ... window, without echoing the password on the screen. ... functions. I did see a Mode function ... -echo command. ... I have some ideas but don t have a
    Message 1 of 2 , Aug 1, 2003
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, <greg.hering@b...> wrote:
      > I need to input a password from a perl program running in a DOS
      window, without echoing the password on the screen.
      >
      > I looked in Win32::Console. I didn' see any passwd() or getpass()
      functions. I did see a 'Mode' function
      >
      > something like
      >
      > $CONSOLE->Alloc();
      >
      > $mode = $CONSOLE->Mode();
      > $CONSOLE->Mode( $mode ^ ENABLE_ECHO_INPUT);
      >
      > but this doesn't work. (rest of code below)
      >
      > Is there a way to turn off character echo, kind of like Unix 'stty
      -echo' command.
      >
      > Thanks,
      >
      > Greg
      >
      >
      > Gregory L. Hering
      > 4807 Bradford Drive
      > Huntsville, AL 35805
      > (256) 722-6420
      >
      >
      >
      >
      > #!/usr/bin/perl -w
      >
      > use strict;
      > use warnings;
      > use diagnostics;
      >
      > use Win32::Console;
      >
      > my $QUIT_STR = "\n";
      >
      > my $con = new Win32::Console(STD_OUTPUT_HANDLE);
      >
      > $con->Free();
      > $con->Alloc();
      >
      > #$con->Attr($::BG_WHITE | $::FG_BLUE);
      >
      > my $mode = $con->Mode();
      > print $mode . "\n";
      >
      > #print ENABLE_ECHO_INPUT . "\n";
      >
      > $con->Mode(ENABLE_LINE_INPUT);
      > $mode = $con->Mode();
      > print $mode . "\n";
      >
      > $con->Mode(!ENABLE_ECHO_INPUT);
      > $mode = $con->Mode();
      > print $mode . "\n";
      >
      >
      > $con->Display();
      > $con->Title("Test Monitor");
      > $con->Size(100,100);
      > $con->Window(1,0,0,80,30);
      >
      >
      > my $buffer;
      > my $quitStrBuf;
      >
      > while (1)
      >
      > {
      > if (read(STDIN, $buffer,1))
      > {
      > if ($buffer ne "\n")
      > {
      > print $quitStrBuf.$buffer;
      > $quitStrBuf = "";
      > }
      > else
      > {
      > $quitStrBuf .= $buffer;
      >
      > last if ($quitStrBuf eq $QUIT_STR);
      > }
      > }
      > }
      >
      > print "Got quit signal $quitStrBuf\n";
      > exit 0;
      >

      I have some ideas but don't have a Windows box to test them on.

      1) $CONSOLE->Mode( $mode ^ ENABLE_ECHO_INPUT);
      I've forgotten my digital logic classes and all about XOR.
      Would the following be any different?
      $CONSOLE->Mode( $mode| !ENABLE_ECHO_INPUT);

      2) Have you tried working with the input handle?
      my $con = new Win32::Console(STD_INPUT_HANDLE);
      I know the chars are being *outputted* but they are coming from the
      input. Worth a try even if it probably won't work.

      3) Perl Cookbook has a recipe for disabling echo. It uses the
      Term::ReadKey module. I don't know if this will work on Windows.
      The recipe is (probably illegally) at:
      http://www.miet.ru/static/secure/internal/book/cdbs/perl/cookbook/ch15_11.htm
    Your message has been successfully submitted and would be delivered to recipients shortly.