Heslo::POSIX

MUDr. Zdenek Kral kral na arcom.cz
Úterý Červen 8 20:25:14 MEST 1999


Pěkný den,
Posílám slíbený skript s POSIXEM k zadání hesla s výpisem indif.znaku.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#!/usr/bin/perl

package Heslo;

sub heslo {

use strict;

$| = 1;

use POSIX qw(:termios_h);

my($term, $oterm, $echo, $noecho, $stdin, $got, $heslo);

$stdin = fileno(STDIN);

$term = POSIX::Termios->new();
$term->getattr($stdin);
$oterm = $term->getlflag();

$echo = ECHO | ECHOK | ICANON;
$noecho = $oterm & ~$echo;

sub cbreac {
                  $term->setlflag($noecho);
                  $term->setcc(VTIME, 1);
                  $term->setattr($stdin, TCSANOW);
}
sub cooked {
                   $term->setlflag($oterm);
                   $term->setcc(VTIME, 0);
                   $term->setattr($stdin, TCSANOW);
}
sub getone {
                   my $key = "";
                   cbreak();
                   sysread(STDIN, $key, 1);
                   cooked();
                   return $key;
}

system(´clear´);
print"Zadej heslo:";

while ( $got !~/ \012 / ) {
           $got = getone();
           print"*";
           $heslo .= $got;
}

$a = \$heslo;
return $a;

}
&heslo();

$vzor = "heslo";

while($$a !~/ \b$vzor\b/) {
          system(´clear´);
          print"Chybně zadané heslo !";
          sleep(2);
          &heslo();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
S pozdravem                                            -ZK-               kral na arcom.cz

 


Další informace o konferenci Perl