#!/perl -w
# NAME: getpwd.pl
# AIM: To quietly get UNECHOED password,
# BUT DOES NOT WORK IN WINDOWS IMPLEMENTATION!!!
# **********************************************
use strict;
use warnings;
use POSIX;
require 'logfile.pl' or die "Unable to load logfile.pl ...\n";
# log file stuff
my ($LF);
my $pgmname = $0;
if ($pgmname =~ /\w{1}:\\.*/) {
	my @tmpsp = split(/\\/,$pgmname);
	$pgmname = $tmpsp[-1];
}
my $outfile = "temp.$pgmname.txt";
open_log($outfile);
prt( "$0 ... Hello, World ...\n" );

# Ask for a user, password, etc
# *****************************
my ($who, $pass, $email);

print "Who are you? ";
chop ($who = <STDIN>);
 
print "What is your password? ";
$pass = pwread();
 
print "What is your email address? ";
chop ($email = <STDIN>);
 
print <<"";
Name: $who
Password: $pass
Email: $email
 
close_log($outfile,1);
exit(0);

sub pwread {
	my ($numfile, $keyboard, $cbset, $lflags, $what, $rstring);
        $| = 1;
        print "";
 
        $numfile = fileno(STDIN);
        $keyboard = new POSIX::Termios ();
        $keyboard -> getattr($numfile);
 
        # switch to cbreak mode
 
        $cbset = $lflags = $keyboard -> getlflag();
        $cbset &= ~(ECHO|ECHOK|ICANON);
        $keyboard -> setlflag($cbset);
        $keyboard -> setcc(VTIME,1);
        $keyboard -> setattr($numfile,TCSANOW);
 
        until (0) {
                sysread(STDIN,$what,1);
                last if ($what =~ /[\n\r]/);
                if ($what =~ /[\x7f\x08]/) {
                        chop $rstring &&
                        print "\x08 \x08";
                } else {
                        $rstring .= $what;
                        print "%";
                        }
                }
 
        # restore cooked mode
 
        $keyboard -> setlflag($lflags);
        $keyboard -> setcc(VTIME,0);
        $keyboard -> setattr($numfile,TCSANOW);
 
        print "\n";
        $| = 0;
        $rstring;
}

# eof - getpwd.pl
