| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::Password::MD5; |
|
2
|
|
|
|
|
|
|
our $VERSION = "0.18"; |
|
3
|
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
16595
|
use Moo; |
|
|
4
|
|
|
|
|
7810
|
|
|
|
4
|
|
|
|
|
25
|
|
|
5
|
4
|
|
|
4
|
|
4502
|
use strictures 2; |
|
|
4
|
|
|
|
|
1673
|
|
|
|
4
|
|
|
|
|
207
|
|
|
6
|
|
|
|
|
|
|
extends 'Text::Password::CoreCrypt'; |
|
7
|
4
|
|
|
4
|
|
844
|
use constant Min => 4; |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
250
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
479
|
use autouse 'Carp' => qw(croak carp); |
|
|
4
|
|
|
|
|
824
|
|
|
|
4
|
|
|
|
|
23
|
|
|
10
|
4
|
|
|
4
|
|
405
|
use autouse 'Crypt::PasswdMD5' => qw(unix_md5_crypt); |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
39
|
|
|
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<DON'T USE> 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
|
3
|
|
|
3
|
1
|
31646
|
my ( $self, $input, $data ) = ( shift, @_ ); |
|
71
|
3
|
50
|
|
|
|
17
|
carp ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
|
72
|
3
|
|
|
|
|
12
|
return $data eq unix_md5_crypt(@_); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head3 nonce( I<Int> ) |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
generates the random strings with enough strength. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
the length defaults to 8 || $self->default(). |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 encrypt( I<Str> ) |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
returns hash with unix_md5_crypt(). |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
salt will be made automatically. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub encrypt { |
|
91
|
3
|
|
|
3
|
1
|
15722
|
my ( $self, $input ) = @_; |
|
92
|
3
|
50
|
|
|
|
12
|
croak ref $self, " requires at least ", Min, " length" if length $input < Min; |
|
93
|
3
|
50
|
|
|
|
14
|
croak ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
|
94
|
|
|
|
|
|
|
|
|
95
|
3
|
|
|
|
|
17
|
my $salt = ''; |
|
96
|
3
|
|
|
|
|
5
|
do { $salt = $self->nonce() } until $salt !~ /\$/; |
|
|
3
|
|
|
|
|
11
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
16
|
return unix_md5_crypt( $input, $salt ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head3 generate( I<Int> ) |
|
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__ |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 LICENSE |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Copyright (C) Yuki Yoshida(worthmine). |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
121
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Yuki Yoshida E<lt>worthmine@users.noreply.github.comE<gt> |