Leser: 1
5 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package My::UserPassword;
use strict;
use warnings;
use Carp;
require Tk;
require Tk::Toplevel;
require Exporter;
our @ISA = qw(Exporter);
our $VERSION = '0.01';
our @list = ();
sub Show{
my ($self) = @_;
my $cw = $self->{cw};
$cw->Popup();
$cw->waitVariable(\$cw->{Selected});
$cw->withdraw;
$cw->{Selected} = [""] unless(defined $cw->{Selected});
return wantarray ? @{$cw->{Selected}} : join("; ",@{$cw->{Selected}});
}# Show
sub Accept{
my ($cw) = @_;
my $user = $cw->Subwidget('user_frame')->Subwidget('user')->get();
my $pass = $cw->Subwidget('password_frame')->Subwidget('password')->get();
$cw->{Selected} = [$user,$pass];
$cw->{Selected} = [""] unless($user && $pass);
}# Accept
sub Cancel{
my ($cw) = @_;
$cw->{Selected} = undef;
$cw->withdraw;
}#Cancel
sub new{
my ($class,$cw,%args) = @_;
my $self = {};
bless($self,$class);
my $top = $cw->Toplevel(%args);
$top->protocol('WM_DELETE_WINDOW' => [\&Cancel, $top]);
# User Frame
my $entry_var = '';
my $user_frm = $top->Component('Frame' => 'user_frame')->pack(-expand => 1, -fill => 'both');
$user_frm->Label(-text => 'User: ')->pack(-anchor => 'w',
-side => 'left',);
$user_frm->Component('Entry' => 'user',
-textvariable => \$entry_var,
)->pack(-anchor => 'e',
-side => 'right',);
# Password Frame
my $password_var = '';
my $pass_frm = $top->Component('Frame' => 'password_frame')->pack(-expand => 1, -fill => 'both');
$pass_frm->Label(-text => 'Password: ')->pack(-anchor => 'w',
-side => 'left',);
$pass_frm->Component('Entry' => 'password',
-textvariable => \$password_var,
-show => '*',
)->pack(-anchor => 'e',
-side => 'right',);
# ok-Button
$top->Button(-text => 'ok', -command => [\&Accept,$top])->pack();
$self->{cw} = $top;
return $self;
}# Populate
1;
1
2
3
my $passwordwidget = My::UserPassword->new($manwindow,%args);
my ($user,$passwd) = $passwordwidget->Show();
print "User:\t\t$user\nPassword:\t$passwd\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use strict;
use warnings;
use Tk;
use Tk::DialogBox;
use Tk::LabEntry;
use prj::cfile;
package prj::login;
sub new
{
my $this = shift;
my $thisref = ref($this) || $this;
my $self;
$self->{'parent'} = $_[0];
$self->{'username'} = "";
$self->{'password'} = "";
# create Login-Dialog
$self->{'window'} = $self->{'parent'}->DialogBox(-title =>'Login', -default_button => 'OK', -buttons => ['OK', 'Abbrechen'] );
$self->{window}->add('LabEntry', -textvariable => \$self->{'username'}, -width => 20,
label => 'Benutzer')->pack(-side =>"top");
$self->{window}->add('LabEntry', -textvariable => \$self->{'password'}, -width => 20,
label => 'Passwort', -show =>'*')->pack(-side =>"top");
bless ($self, $thisref);
return $self;
}
sub getpass
{
my $self = shift;
my @heads = ('id', 'name', 'pass', 'grants', 'local', 'server');
my $userdb = prj::cfile->new(@heads, 'dat\\users.dat');
my $result = $self->{'window'}->Show();
$self->{'window'}->bind("<Return>", sub{$result = 'OK';});
$self->{'window'}->bind("<Escape>", sub{print "abbruch!\n"; $result = 'Abbrechen';});
if ('OK' eq $result)
{
my %find = ( 'name' => $self->{'username'}, 'pass' => $self->{'password'});
my @datarray = @{$userdb->get(\%find)};
my %data = %{$datarray[0]};
if (@datarray == 1)
{
return \%data;
}
}
return 0;
}
return 1;
5 Einträge, 1 Seite |