String/Password.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« String/Parse.pm ↑ Summary String/Psv.pm »
1 #
2 # $Id$
3 #
4 # string::password Brik
5 #
6 package Metabrik::String::Password;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable random) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 charset => [ qw($character_list) ],
20 length => [ qw(integer) ],
21 count => [ qw(integer) ],
22 },
23 attributes_default => {
24 charset => [ 'A'..'K', 'M'..'Z', 'a'..'k', 'm'..'z', 2..9, '_', '-', '#', '!' ],
25 length => 10,
26 count => 5,
27 },
28 commands => {
29 generate => [ qw(length|OPTIONAL count|OPTIONAL) ],
30 prompt => [ qw(string|OPTIONAL) ],
31 },
32 require_modules => {
33 'String::Random' => [ ],
34 'Term::ReadPassword' => [ ],
35 },
36 };
37 }
38  
39 sub generate {
40 my $self = shift;
41 my ($length, $count) = @_;
42  
43 $length ||= $self->length;
44 $count ||= $self->count;
45  
46 my $charset = $self->charset;
47  
48 my $rand = String::Random->new;
49 $rand->{A} = $charset;
50  
51 my @passwords = ();
52 for (1..$count) {
53 push @passwords, $rand->randpattern("A"x$length);
54 }
55  
56 return \@passwords;
57 }
58  
59 sub prompt {
60 my $self = shift;
61 my ($string) = @_;
62  
63 $string ||= 'Password: ';
64  
65 my $password;
66 while (1) {
67 my $this = Term::ReadPassword::read_password($string);
68 if (defined($this)) {
69 $password = $this;
70 last;
71 }
72 }
73  
74 return $password;
75 }
76  
77 1;
78  
79 __END__
« String/Parse.pm ↑ Summary String/Psv.pm »