use strict; use warnings;
Class_Main: { MyApp->new->run; }
Class_MyApp: { package MyApp; use Win32::GUI qw( MB_ICONINFORMATION MB_OK );;
sub new { my $class = shift; my $self = {@_};
bless $self, $class;
$self->interface;
return $self; }
sub run { my $self = shift;
$self->{win}->Show(); Win32::GUI::Dialog();
}
sub display_password { my $self = shift;
use String::MkPasswd qw(mkpasswd);
my $passwd = mkpasswd( -length => 9, -minnum => 2, -minlower => 2, # minlower is increased if necessary
-minupper => 2, -minspecial => 2, -distribute => 1, );
$self->{win}->MessageBox( $passwd, "您的密码", MB_ICONINFORMATION | MB_OK, ); }
sub display_help { my $self = shift;
my $message = "密码长度:您需要的密码位数。默认是9位。\r\n" . "数字个数:您的密码中最少有几个数字。默认最少2个。\r\n" . "小写字母:您的密码中最少有几个小写字母。默认最少2个。\r\n" . "大写字母:您的密码中最少有几个大写字母。默认最少2个。\r\n" . "特殊符号:您的密码中最少有几个特殊符号。默认最少1个。\r\n" . "键盘分布:如果选'是',密码会均匀分布。默认为否。\r\n";
$self->{win}->MessageBox( $message, "帮助", MB_ICONINFORMATION | MB_OK, );
}
sub interface {
my $self = shift;
$self->{win} = Win32::GUI::Window->new( -name => 'Main', -width => 200, -height => 200, -text => '随机密码生成器', );
$self->{win}->AddButton( -name => "Button_Generate", -text => "生成", -pos => [ 30, 140 ], -onClick => sub { $self->display_password;}, );
$self->{win}->AddButton( -name => "Button_Exit", -text => "退出", -pos => [ 80, 140 ], -onClick => sub { return -1; }, );
$self->{win}->AddButton( -name => "Button_Help", -text => "帮助", -pos => [ 130, 140 ], -onClick => sub { $self->display_help; }, );
$self->{win}->AddTextfield( -align => 'right', -name => "length", -left => 80, -top => 5, -width => 80, -height => 20, -prompt => "密码长度:", -number => 1, -text => 9, );
$self->{win}->AddTextfield( -align => 'right', -name => "minnum", -left => 80, -top => 25, -width => 80, -height => 20, -prompt => "数字个数:", -number => 1, -text => 2, );
$self->{win}->AddTextfield( -align => 'right', -name => "minlower", -left => 80, -top => 45, -width => 80, -height => 20, -prompt => "小写字母:", -number => 1, -text => 2, );
$self->{win}->AddTextfield( -align => 'right', -name => "minupper", -left => 80, -top => 65, -width => 80, -height => 20, -prompt => "大写字母:", -number => 1, -text => 2, );
$self->{win}->AddTextfield( -align => 'right', -name => "minspecial", -left => 80, -top => 85, -width => 80, -height => 20, -prompt => "特殊符号:", -number => 1, -text => 1, );
$self->{win}->AddLabel( -text => "键盘分布:", -pos => [21, 112], );
$self->{win}->AddRadioButton( -name => "distribute_yes", -text => '是', -pos => [85, 110], -size => [50, 20], -checked => 0 ); $self->{win}->AddRadioButton( -name => "distribute_no", -text => '否', -pos => [125, 110], -size => [50, 20], -tabstop => 1, -checked => 1, );
return $self; }
}
|