line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Password::MD5; |
2
|
|
|
|
|
|
|
our $VERSION = "0.17"; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
15743
|
use Moo; |
|
4
|
|
|
|
|
7832
|
|
|
4
|
|
|
|
|
26
|
|
5
|
4
|
|
|
4
|
|
3535
|
use strictures 2; |
|
4
|
|
|
|
|
3365
|
|
|
4
|
|
|
|
|
197
|
|
6
|
4
|
|
|
4
|
|
1299
|
use autouse 'Carp' => qw(croak carp); |
|
4
|
|
|
|
|
807
|
|
|
4
|
|
|
|
|
40
|
|
7
|
4
|
|
|
4
|
|
445
|
use autouse 'Crypt::PasswdMD5' => qw(unix_md5_crypt); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
31
|
|
8
|
4
|
|
|
4
|
|
366
|
use constant Min => 4; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1247
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=encoding utf-8 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Text::Password::MD5 - generate and verify Password with unix_md5_crypt() |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $pwd = Text::Password::MD5->new(); |
19
|
|
|
|
|
|
|
my( $raw, $hash ) = $pwd->genarate(); # list context is required |
20
|
|
|
|
|
|
|
my $input = $req->body_parameters->{passwd}; |
21
|
|
|
|
|
|
|
my $data = $pwd->encrypt($input); # you don't have to care about salt |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $flag = $pwd->verify( $input, $data ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Text::Password::MD5 is the part of Text::Password::AutoMigration. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
B<DON'T USE> directly. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 Constructor and initialization |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head3 new() |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
No arguments are required. But you can set some parameters. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item default |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
You can set default length with param 'default' like below: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$pwd = Text::Pasword::AutoMiglation->new( default => 12 ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item readablity |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Or you can set default strength for password with param 'readablity'. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
It must be a boolean, default is 1. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
If it was set as 0, you can generate stronger passwords with generate(). |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$pwd = Text::Pasword::AutoMiglation->new( readability => 0 ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 Methods and Subroutines |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 verify( $raw, $hash ) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
returns true if the verification succeeds. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
extends 'Text::Password::CoreCrypt'; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub verify { |
68
|
3
|
|
|
3
|
1
|
31721
|
my ( $self, $input, $data ) = ( shift, @_ ); |
69
|
3
|
50
|
|
|
|
13
|
carp ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
70
|
3
|
|
|
|
|
12
|
return $data eq unix_md5_crypt(@_); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head3 nonce( I<Int> ) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
generates the random strings with enough strength. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
the length defaults to 8 || $self->default(). |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head3 encrypt( I<Str> ) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
returns hash with unix_md5_crypt(). |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
salt will be made automatically. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub encrypt { |
90
|
3
|
|
|
3
|
1
|
15753
|
my ( $self, $input ) = @_; |
91
|
3
|
50
|
|
|
|
10
|
croak ref $self, " requires at least ", Min, " length" if length $input < Min; |
92
|
3
|
50
|
|
|
|
9
|
croak ref $self, " doesn't allow any Wide Characters or white spaces" if $input =~ /[^ -~]/; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
9
|
my $salt = ''; |
95
|
3
|
|
|
|
|
5
|
do { $salt = $self->nonce() } until $salt !~ /\$/; |
|
3
|
|
|
|
|
18
|
|
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
10
|
return unix_md5_crypt( $input, $salt ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head3 generate( I<Int> ) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
genarates pair of new password and it's hash. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
less readable characters I<(0Oo1Il|!2Zz5sS$6b9qCcKkUuVvWwXx.,:;~-^'"`)> |
105
|
|
|
|
|
|
|
are forbiddenunless $self->readability is 0. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
the length defaults to 8 || $self->default(). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright (C) Yuki Yoshida(worthmine). |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
120
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Yuki Yoshida E<lt>worthmine@users.noreply.github.comE<gt> |