CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
w32 password prompting with random char array.

 



sirgrim
New User

Feb 10, 2003, 8:07 AM

Post #1 of 1 (2627 views)
w32 password prompting with random char array. Can't Post

Ever writing a w32 program that requires password prompting?

Don't want your password displayed on screen, ReadKey not a w32 module?

Here's a fix! Guaranteed to work and replaces the chars with a random array.

Enjoy. Tongue

# $language = "PerlScript"
# $interface = "1.0"

## Windows Password Prompting w/ random array replacement of chars ##
## Free script, enjoy, by sirgrim/WAGD. ##

use strict;
use IO::Socket;
use warnings;
use Getopt::Long;
use Win32::Console;
srand;

## Clear Buffer ##
my $oldh = select(STDOUT);
$| = 1;
select($oldh);
## End Clear Buffer ##

## Console Handling ##
my $cons = new Win32::Console(STD_INPUT_HANDLE); ## Creates New to work with all procs.
#my ($x, $y, $size, $visible) = $cons->Cursor(); ## Depicts Console Size and Location.
## End Console Handling ##

user_pass(); ## Runs the damn thing.

## just for fun. Random array of chars for Password Entry.##
sub random_array {
my @array = ('*', '&+', '!', '@', '^{@', '%~=', '#', '%!', '^*', '$#', '&%@', '@!', '$', '%', '^', '{*^', '}', '~', '`', '+', '?');
my $index = rand @array;
my $element = $array[$index];
return $element;
}
## end fun, go work. ##

## Password Prompting ##
sub user_pass {
print "\nWhat is the User Password? ";
my $password;
my $char;
my $oldMode = $cons->Mode; ## Sets old mode before changes.
$cons->Mode(~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT) & $oldMode );
while(1) {
$char = $cons->InputChar(1); ##input from keyboard
if($char || ord $char == 48) { ## allows 0s
last if ord $char == 13;
print random_array(); ; ##displays a random array for each char.
$password .= $char ; ##sets password.
}
}
$cons->Mode($oldMode); ## Returns to Normal.
if(!$password) { die "\n\nPlease enter a password.\n"; } ## Kills program if left empty.
return $password; ## Returns password for others to know about.
}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives