#!/usr/bin/perl use strict; use Win32::Console; my $usrnam = get_username(); my $usrpwd = get_password(); while (1) { my $inpflg = 0; my $geninp; while (!$inpflg) { print "Command: "; chomp ($geninp = ); my $tstinp = $geninp; $tstinp =~ s/^\s+//g; $tstinp =~ s/\s+$//g; if ($tstinp ne '') { $inpflg = 1; } } if ($geninp =~ /exit/) { exit; } elsif ($geninp =~ /go/) { print "Username: $usrnam\n"; print "Password: $usrpwd\m"; } } sub getpass() { # Establish a console control object my $cnsbuf; # our $cnsbuf; if (!$cnsbuf) { $cnsbuf = new Win32::Console(STD_INPUT_HANDLE); } if (!$cnsbuf) { return(undef); } # Ensure console ECHO is OFF my $oldmod = $cnsbuf->Mode(); if ($oldmod & ENABLE_ECHO_INPUT) { my $newmod = ($oldmod ^ ENABLE_ECHO_INPUT); $cnsbuf->Mode($newmod); } # Go get the password my $usrpas = ; chomp($usrpas); # Return console to old mode $cnsbuf->Mode($oldmod); # Print the missing newline print "\n"; # Give 'em what they asked for return($usrpas); } sub get_username() { print "Username: "; chomp (my $wrknam = ); return $wrknam; } sub get_password() { print "Password: "; chomp (my $wrkpas = &getpass()); return $wrkpas; }