[Perl TK] GenPassword

Iniciado por BigBear, Julio 03, 2011, 10:01:06 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Julio 03, 2011, 10:01:06 PM Ultima modificación: Julio 17, 2011, 03:43:14 AM por Sthefano02
Un simple generador de contraseñas

Imagen






Código: perl

#!usr/bin/perl
#Gen Password (C) Doddy Hackman 2011

use Tk;

if ($^O eq 'MSWin32') {
use Win32::Console;
Win32::Console::Free();
}

my $sin = MainWindow->new();
$sin->title("Gen Password (C) Doddy Hackman 2011");
$sin->geometry("530x80+20+20");
$sin->resizable(0,0);

$sin->Label(-text=>"Result : ",-font=>"Impact1")->place(-x=>30,-y=>20);
my $rex = $sin->Text(-width=>28,-height=>1)->place(-y=>24,-x=>90);
$sin->Label(-text=>"Length : ",-font=>"Impact1")->place(-x=>310,-y=>20);
my $leng = $sin->Entry(-width=>3,-text=>3)->place(-y=>24,-x=>370);
$sin->Button(-text=>"Generate",-command=>\&gen,-width=>12)->place(-y=>22,-x=>410);

MainLoop;


sub gen {

$rex->delete("0.0","end");
my $ala = $leng->get;

my @password = genpass($ala);
for $pass(@password) {
$rex->insert("end",$pass);
}}

sub genpass {

my $length = shift;

my @re;

my @mayus = (A..Z);
my @minus = (a..z);
my @number = (0..9);
my @op = (1..3);

for (1..$length) {

my $opt = @op[rand(@op)];
if ($opt eq 1) {
push(@re,@mayus[rand(@mayus)]);
}
elsif ($opt eq 2) {
push(@re,@minus[rand(@minus)]);
}
elsif ($opt eq 3) {
push(@re,@number[rand(@number)]);
}
}
return @re;
}

#Thanks to explorer (perlenespanol)
# ¿ The End ?