line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Passphrase::Bcrypt; |
2
|
|
|
|
|
|
|
$Crypt::Passphrase::Bcrypt::VERSION = '0.007'; |
3
|
1
|
|
|
1
|
|
547
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Crypt::Passphrase 0.010 -encoder; |
|
1
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5931
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
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
|
|
|
|
|
408
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %supported_prehash = map { $_ => 1 } bcrypt_supported_prehashes(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
2
|
|
|
2
|
1
|
394
|
my ($class, %args) = @_; |
15
|
2
|
|
50
|
|
|
16
|
my $subtype = $args{subtype} // '2b'; |
16
|
2
|
50
|
|
|
|
12
|
croak "Unknown subtype $subtype" unless $subtype =~ / \A 2 [abxy] \z /x; |
17
|
2
|
|
100
|
|
|
8
|
my $hash = $args{hash} // ''; |
18
|
2
|
50
|
66
|
|
|
12
|
croak 'Invalid hash' if length $args{hash} and not $supported_prehash{ $args{hash} }; |
19
|
|
|
|
|
|
|
return bless { |
20
|
2
|
|
50
|
|
|
17
|
cost => $args{cost} // 14, |
21
|
|
|
|
|
|
|
subtype => $subtype, |
22
|
|
|
|
|
|
|
hash => $hash, |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub hash_password { |
27
|
2
|
|
|
2
|
1
|
245
|
my ($self, $password) = @_; |
28
|
2
|
|
|
|
|
11
|
my $salt = $self->random_bytes(16); |
29
|
2
|
|
|
|
|
10576
|
return bcrypt_prehashed($password, $self->{subtype}, $self->{cost}, $salt, $self->{hash}); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub needs_rehash { |
33
|
5
|
|
|
5
|
1
|
5847946
|
my ($self, $hash) = @_; |
34
|
5
|
|
|
|
|
16
|
return bcrypt_needs_rehash($hash, @{$self}{qw/subtype cost hash/}); |
|
5
|
|
|
|
|
54
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub crypt_subtypes { |
38
|
2
|
|
|
2
|
1
|
3347382
|
return (qw/2a 2b 2x 2y/, map { "bcrypt-$_" } bcrypt_supported_prehashes()); |
|
6
|
|
|
|
|
50
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub verify_password { |
42
|
6
|
|
|
6
|
1
|
2922038
|
my ($class, $password, $hash) = @_; |
43
|
6
|
|
|
|
|
46
|
return bcrypt_check_prehashed($password, $hash); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub binary_safe { |
47
|
0
|
|
|
0
|
0
|
|
return 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#ABSTRACT: A bcrypt encoder for Crypt::Passphrase |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |