| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::Password::MD5; |
|
2
|
|
|
|
|
|
|
our $VERSION = "0.43"; |
|
3
|
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
260441
|
use Moo; |
|
|
4
|
|
|
|
|
6186
|
|
|
|
4
|
|
|
|
|
26
|
|
|
5
|
4
|
|
|
4
|
|
4237
|
use strictures 2; |
|
|
4
|
|
|
|
|
1402
|
|
|
|
4
|
|
|
|
|
222
|
|
|
6
|
|
|
|
|
|
|
extends 'Text::Password::CoreCrypt'; |
|
7
|
4
|
|
|
4
|
|
2130
|
use constant Min => 4; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
313
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
353
|
use autouse 'Carp' => qw(croak carp); |
|
|
4
|
|
|
|
|
700
|
|
|
|
4
|
|
|
|
|
41
|
|
|
10
|
4
|
|
|
4
|
|
523
|
use autouse 'Crypt::PasswdMD5' => qw(unix_md5_crypt); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf-8 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Text::Password::MD5 - generate and verify Password with unix_md5_crypt() |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $pwd = Text::Password::MD5->new(); |
|
21
|
|
|
|
|
|
|
my( $raw, $hash ) = $pwd->generate(); # list context is required |
|
22
|
|
|
|
|
|
|
my $input = $req->body_parameters->{passwd}; |
|
23
|
|
|
|
|
|
|
my $data = $pwd->encrypt($input); # you don't have to care about salt |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $flag = $pwd->verify( $input, $data ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Text::Password::MD5 is the part of Text::Password::AutoMigration. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
B directly. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 Constructor and initialization |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head3 new() |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
No arguments are required. But you can set some parameters. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item default |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
You can set default length with param 'default' like below: |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$pwd = Text::Password::AutoMiglation->new( default => 12 ); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item readablity |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Or you can set default strength for password with param 'readablity'. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
It must be a boolean, default is 1. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
If it was set as 0, you can generate stronger passwords with generate(). |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$pwd = Text::Password::AutoMiglation->new( readability => 0 ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 Methods and Subroutines |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head3 verify( $raw, $hash ) |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
returns true if the verification succeeds. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub verify { |
|
70
|
503
|
|
|
503
|
1
|
6999074
|
my ( $self, $input, $data ) = ( shift, @_ ); |
|
71
|
503
|
50
|
|
|
|
3562
|
carp ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
|
72
|
503
|
|
|
|
|
3416
|
return $data eq unix_md5_crypt(@_); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head3 nonce( I ) |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
generates the random strings with enough strength. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
the length defaults to 8 || $self->default(). |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 encrypt( I ) |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
returns hash with unix_md5_crypt(). |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
salt will be made automatically. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub encrypt { |
|
91
|
503
|
|
|
503
|
1
|
12554
|
my ( $self, $input ) = @_; |
|
92
|
503
|
50
|
|
|
|
1607
|
croak ref $self, " requires at least ", Min, " length" if length $input < Min; |
|
93
|
503
|
50
|
|
|
|
2028
|
croak ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
|
94
|
|
|
|
|
|
|
|
|
95
|
503
|
|
|
|
|
1176
|
my $salt = ''; |
|
96
|
503
|
|
|
|
|
1156
|
do { $salt = $self->nonce() } until $salt !~ /\$/; |
|
|
503
|
|
|
|
|
1284
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
503
|
|
|
|
|
3940
|
return unix_md5_crypt( $input, $salt ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head3 generate( I ) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
generates pair of new password and its hash. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
less readable characters I<(0Oo1Il|!2Zz5sS$6b9qCcKkUuVvWwXx.,:;~-^'"`)> |
|
106
|
|
|
|
|
|
|
are forbiddenunless $self->readability is 0. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
the length defaults to 8 || $self->default(). |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |