| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Crypt::Passphrase::Bcrypt; |
|
2
|
|
|
|
|
|
|
$Crypt::Passphrase::Bcrypt::VERSION = '0.006'; |
|
3
|
1
|
|
|
1
|
|
598
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
14
|
use Crypt::Passphrase 0.010 -encoder; |
|
|
1
|
|
|
|
|
25
|
|
|
|
1
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6065
|
use Carp 'croak'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
72
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use Crypt::Bcrypt 0.011 qw/bcrypt bcrypt_prehashed bcrypt_check_prehashed bcrypt_needs_rehash bcrypt_supported_prehashes/; |
|
|
1
|
|
|
|
|
20
|
|
|
|
1
|
|
|
|
|
726
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %supported_prehash = map { $_ => 1 } bcrypt_supported_prehashes(); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
2
|
|
|
2
|
1
|
374
|
my ($class, %args) = @_; |
|
15
|
2
|
|
50
|
|
|
19
|
my $subtype = $args{subtype} // '2b'; |
|
16
|
2
|
50
|
|
|
|
13
|
croak "Unknown subtype $subtype" unless $subtype =~ / \A 2 [abxy] \z /x; |
|
17
|
2
|
|
100
|
|
|
9
|
my $hash = $args{hash} // ''; |
|
18
|
2
|
50
|
66
|
|
|
14
|
croak 'Invalid hash' if length $args{hash} and not $supported_prehash{ $args{hash} }; |
|
19
|
|
|
|
|
|
|
return bless { |
|
20
|
2
|
|
50
|
|
|
19
|
cost => $args{cost} // 14, |
|
21
|
|
|
|
|
|
|
subtype => $subtype, |
|
22
|
|
|
|
|
|
|
hash => $hash, |
|
23
|
|
|
|
|
|
|
}, $class; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub hash_password { |
|
27
|
2
|
|
|
2
|
1
|
246
|
my ($self, $password) = @_; |
|
28
|
2
|
|
|
|
|
13
|
my $salt = $self->random_bytes(16); |
|
29
|
2
|
|
|
|
|
10351
|
return bcrypt_prehashed($password, $self->{subtype}, $self->{cost}, $salt, $self->{hash}); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub needs_rehash { |
|
33
|
5
|
|
|
5
|
1
|
5847711
|
my ($self, $hash) = @_; |
|
34
|
5
|
|
|
|
|
16
|
return bcrypt_needs_rehash($hash, @{$self}{qw/subtype cost hash/}); |
|
|
5
|
|
|
|
|
75
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub crypt_subtypes { |
|
38
|
2
|
|
|
2
|
1
|
3340439
|
return (qw/2a 2b 2x 2y/, map { "bcrypt-$_" } bcrypt_supported_prehashes()); |
|
|
6
|
|
|
|
|
50
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub verify_password { |
|
42
|
6
|
|
|
6
|
1
|
2923762
|
my ($class, $password, $hash) = @_; |
|
43
|
6
|
|
|
|
|
41
|
return bcrypt_check_prehashed($password, $hash); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#ABSTRACT: A bcrypt encoder for Crypt::Passphrase |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |