line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Passphrase::Bcrypt; |
2
|
|
|
|
|
|
|
$Crypt::Passphrase::Bcrypt::VERSION = '0.005'; |
3
|
1
|
|
|
1
|
|
73947
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
421
|
use parent 'Crypt::Passphrase::Encoder'; |
|
1
|
|
|
|
|
276
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8718
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
9
|
1
|
|
|
1
|
|
7
|
use Crypt::Bcrypt 0.010 qw/bcrypt bcrypt_prehashed bcrypt_check_prehashed bcrypt_needs_rehash/; |
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
324
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
1
|
444
|
my ($class, %args) = @_; |
13
|
2
|
|
50
|
|
|
19
|
my $subtype = $args{subtype} || '2b'; |
14
|
2
|
50
|
|
|
|
16
|
croak "Unknown subtype $subtype" unless $subtype =~ / \A 2 [abxy] \z /x; |
15
|
2
|
50
|
66
|
|
|
14
|
croak 'Invalid hash' if exists $args{hash} && $args{hash} ne 'sha256'; |
16
|
|
|
|
|
|
|
return bless { |
17
|
|
|
|
|
|
|
cost => $args{cost} || 14, |
18
|
|
|
|
|
|
|
subtype => $subtype, |
19
|
2
|
|
50
|
|
|
20
|
hash => $args{hash} || '', |
|
|
|
100
|
|
|
|
|
20
|
|
|
|
|
|
|
}, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub hash_password { |
24
|
2
|
|
|
2
|
1
|
17
|
my ($self, $password) = @_; |
25
|
2
|
|
|
|
|
18
|
my $salt = $self->random_bytes(16); |
26
|
2
|
|
|
|
|
10517
|
return bcrypt_prehashed($password, $self->{subtype}, $self->{cost}, $salt, $self->{hash}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub needs_rehash { |
30
|
5
|
|
|
5
|
1
|
5841062
|
my ($self, $hash) = @_; |
31
|
5
|
|
|
|
|
18
|
return bcrypt_needs_rehash($hash, @{$self}{qw/subtype cost hash/}); |
|
5
|
|
|
|
|
36
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub crypt_subtypes { |
35
|
0
|
|
|
0
|
1
|
0
|
return qw/2a 2b 2x 2y bcrypt-sha256/; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub verify_password { |
39
|
6
|
|
|
6
|
1
|
6257819
|
my ($class, $password, $hash) = @_; |
40
|
6
|
|
|
|
|
52
|
return bcrypt_check_prehashed($password, $hash); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#ABSTRACT: A bcrypt encoder for Crypt::Passphrase |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |