line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Password::SHA; |
2
|
|
|
|
|
|
|
our $VERSION = "0.16"; |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
2820
|
use Moose; |
|
3
|
|
|
|
|
462220
|
|
|
3
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
extends 'Text::Password::MD5'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
8
|
3
|
|
|
3
|
|
20480
|
no Moose; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
680
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
230
|
|
11
|
3
|
|
|
3
|
|
1916
|
use Digest::SHA qw(sha1_hex); |
|
3
|
|
|
|
|
10311
|
|
|
3
|
|
|
|
|
258
|
|
12
|
3
|
|
|
3
|
|
4036
|
use Crypt::Passwd::XS; |
|
3
|
|
|
|
|
1433
|
|
|
3
|
|
|
|
|
1509
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=encoding utf-8 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Text::Password::SHA - generate and verify Password with SHA |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $pwd = Text::Password::SHA->new(); |
23
|
|
|
|
|
|
|
my( $raw, $hash ) = $pwd->genarate(); # list context is required |
24
|
|
|
|
|
|
|
my $input = $req->body_parameters->{passwd}; |
25
|
|
|
|
|
|
|
my $data = $pwd->encrypt($input); # salt is made automatically |
26
|
|
|
|
|
|
|
my $flag = $pwd->verify( $input, $data ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Text::Password::SHA is the part of Text::Password::AutoMigration. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 Constructor and initialization |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head3 new() |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
No arguments are required. But you can set some parameters. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item default |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
You can set default length with param 'default' like below: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$pwd = Text::Pasword::AutoMiglation->new( default => 12 ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item readablity |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Or you can set default strength for password with param 'readablity'. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
It must be a boolean, default is 1. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
If it was set as 0, you can generate stronger passwords with generate(). |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$pwd = Text::Pasword::AutoMiglation->new( readability => 0 ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Methods and Subroutines |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head3 verify( $raw, $hash ) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
returns true if the verification succeeds. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub verify { |
67
|
308
|
|
|
308
|
1
|
2723
|
my $self = shift; |
68
|
308
|
|
|
|
|
595
|
my ( $input, $data ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
308
|
50
|
|
|
|
803
|
carp "Empty data strings" unless length $data; |
71
|
|
|
|
|
|
|
|
72
|
308
|
100
|
|
|
|
565698
|
return $data eq Crypt::Passwd::XS::unix_sha512_crypt( $input, $data ) |
73
|
|
|
|
|
|
|
if $data =~ /^\$6\$[!-~]{1,8}\$[!-~]{86}$/; |
74
|
203
|
100
|
|
|
|
6888
|
return $data eq Crypt::Passwd::XS::unix_sha256_crypt( $input, $data ) |
75
|
|
|
|
|
|
|
if $data =~ /^\$5\$([!-~]{1,8})\$[!-~]{43}$/; |
76
|
202
|
100
|
|
|
|
409
|
return $data eq sha1_hex($input) if $data =~ /^[0-9a-f]{40}$/i; |
77
|
201
|
|
|
|
|
984
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head3 nonce($length) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
generates the random strings with enough strength. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
the length defaults to 8($self->default). |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head3 encrypt($raw) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
returns hash with unix_sha512_crypt(). |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
salt will be made automatically. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub encrypt { |
95
|
308
|
|
|
308
|
1
|
1728
|
my $self = shift; |
96
|
308
|
|
|
|
|
481
|
my $input = shift; |
97
|
308
|
|
|
|
|
9114
|
my $min = $self->minimum(); |
98
|
308
|
100
|
|
|
|
1032
|
croak ref($self) ." requires at least $min length" if length $input < $min; |
99
|
307
|
100
|
|
|
|
993
|
croak ref($self). " doesn't allow any Wide Characters or white spaces\n" if $input =~ /[^ -~]/; |
100
|
|
|
|
|
|
|
|
101
|
306
|
|
|
|
|
960
|
return Crypt::Passwd::XS::unix_sha512_crypt( $input, $self->_salt() ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head3 generate($length) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
genarates pair of new password and it's hash. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
less readable characters(0Oo1Il|!2Zz5sS$6b9qCcKkUuVvWwXx.,:;~-^'"`) are forbidden |
113
|
|
|
|
|
|
|
unless $self->readability is 0. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
the length defaults to 8($self->default). |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 LICENSE |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Copyright (C) Yuki Yoshida(worthmine). |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
122
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Yuki Yoshida(worthmine) E<lt>worthmine!at!gmail.comE<gt> |