| 1 | package PHP::Functions::Password; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Crypt::Eksblowfish (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Crypt::OpenSSL::Random (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use MIME::Base64 qw(encode_base64 decode_base64); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Readonly qw(Readonly); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use version 0.77 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | our @EXPORT; | |||||||||||||||||||||||||||
| 13 | 6 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 14 | password_algos | ||||||||||||||||||||||||||||
| 15 | password_get_info | ||||||||||||||||||||||||||||
| 16 | password_hash | ||||||||||||||||||||||||||||
| 17 | password_needs_rehash | ||||||||||||||||||||||||||||
| 18 | password_verify | ||||||||||||||||||||||||||||
| 19 | PASSWORD_BCRYPT | ||||||||||||||||||||||||||||
| 20 | PASSWORD_ARGON2I | ||||||||||||||||||||||||||||
| 21 | PASSWORD_ARGON2ID | ||||||||||||||||||||||||||||
| 22 | PASSWORD_DEFAULT | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | 6 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 25 | 'all' => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 26 | 'default' => \@EXPORT, | ||||||||||||||||||||||||||||
| 27 | 'consts' => [ grep /^PASSWORD_/, @EXPORT_OK ], | ||||||||||||||||||||||||||||
| 28 | 'funcs' => [ grep /^password_/, @EXPORT_OK ], | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | 6 | our $VERSION = '1.12'; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Exported constants | ||||||||||||||||||||||||||||
| 34 | 6 | ▶ | use constant PASSWORD_BCRYPT => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | use constant PASSWORD_ARGON2I => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use constant PASSWORD_ARGON2ID => 3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | use constant PASSWORD_DEFAULT => PASSWORD_BCRYPT; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Internal constants | ||||||||||||||||||||||||||||
| 41 | 6 | Readonly my $PASSWORD_BCRYPT_DEFAULT_COST => 10; # no such PHP constant | |||||||||||||||||||||||||||
| 42 | 6 | Readonly my $PASSWORD_ARGON2_DEFAULT_SALT_LENGTH => 16; # no such PHP constant | |||||||||||||||||||||||||||
| 43 | 6 | Readonly my $PASSWORD_ARGON2_DEFAULT_MEMORY_COST => 65536; | |||||||||||||||||||||||||||
| 44 | 6 | Readonly my $PASSWORD_ARGON2_DEFAULT_TIME_COST => 4; | |||||||||||||||||||||||||||
| 45 | 6 | Readonly my $PASSWORD_ARGON2_DEFAULT_THREADS => 1; | |||||||||||||||||||||||||||
| 46 | 6 | Readonly my $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH => 32; # no such PHP constant | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 6 | Readonly my $SIG_BCRYPT => '2y'; # PHP default | |||||||||||||||||||||||||||
| 49 | 6 | Readonly my $SIG_ARGON2I => 'argon2i'; | |||||||||||||||||||||||||||
| 50 | 6 | Readonly my $SIG_ARGON2ID => 'argon2id'; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | Readonly my %SIG_TO_ALGO => ( | |||||||||||||||||||||||||||
| 53 | $SIG_BCRYPT => PASSWORD_BCRYPT, | ||||||||||||||||||||||||||||
| 54 | $SIG_ARGON2I => PASSWORD_ARGON2I, | ||||||||||||||||||||||||||||
| 55 | $SIG_ARGON2ID => PASSWORD_ARGON2ID, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # https://en.wikipedia.org/wiki/Bcrypt | ||||||||||||||||||||||||||||
| 59 | 6 | Readonly my $RE_BCRYPT_ALGO => qr#2[abxy]?#; | |||||||||||||||||||||||||||
| 60 | 6 | Readonly my $RE_BCRYPT_SALT => qr#[./A-Za-z0-9]{22}#; # fixed 16 byte salt | |||||||||||||||||||||||||||
| 61 | 6 | Readonly my $RE_BCRYPT_COST => qr#[0-3]\d#; | |||||||||||||||||||||||||||
| 62 | 6 | Readonly my $RE_BCRYPT_HASH => qr#[./A-Za-z0-9]+#; | |||||||||||||||||||||||||||
| 63 | 6 | Readonly my $RE_BCRYPT_STRING => qr/^ | |||||||||||||||||||||||||||
| 64 | \$ | ||||||||||||||||||||||||||||
| 65 | ($RE_BCRYPT_ALGO) # $1 type | ||||||||||||||||||||||||||||
| 66 | \$ | ||||||||||||||||||||||||||||
| 67 | ($RE_BCRYPT_COST) # $2 cost | ||||||||||||||||||||||||||||
| 68 | \$ | ||||||||||||||||||||||||||||
| 69 | ($RE_BCRYPT_SALT) # $3 salt | ||||||||||||||||||||||||||||
| 70 | ($RE_BCRYPT_HASH) # $4 hash | ||||||||||||||||||||||||||||
| 71 | $/x; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # See https://www.alexedwards.net/blog/how-to-hash-and-verify-passwords-with-argon2-in-go | ||||||||||||||||||||||||||||
| 74 | 6 | Readonly my $RE_ARGON2_ALGO => qr#argon2id?#; | |||||||||||||||||||||||||||
| 75 | 6 | Readonly my $RE_ARGON2_STRING => qr/^ | |||||||||||||||||||||||||||
| 76 | \$ | ||||||||||||||||||||||||||||
| 77 | ($RE_ARGON2_ALGO) # $1 signature | ||||||||||||||||||||||||||||
| 78 | \$ | ||||||||||||||||||||||||||||
| 79 | v=(\d{1,3}) # $2 version | ||||||||||||||||||||||||||||
| 80 | \$ | ||||||||||||||||||||||||||||
| 81 | m=(\d{1,10}), # $3 memory_cost | ||||||||||||||||||||||||||||
| 82 | t=(\d{1,3}), # $4 time_cost | ||||||||||||||||||||||||||||
| 83 | p=(\d{1,3}) # $5 threads | ||||||||||||||||||||||||||||
| 84 | \$ | ||||||||||||||||||||||||||||
| 85 | ([A-Za-z0-9+\/]+) # $6 salt | ||||||||||||||||||||||||||||
| 86 | \$ | ||||||||||||||||||||||||||||
| 87 | ([A-Za-z0-9+\/]+) # $7 hash | ||||||||||||||||||||||||||||
| 88 | $/x; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 NAME | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | PHP::Functions::Password - Perl ports of PHP password functions | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | This module provides ported PHP password functions. | ||||||||||||||||||||||||||||
| 97 | This module supports the bcrypt, argon2i, and argon2id algorithms, as is the case with the equivalent PHP functions at the date of writing this. | ||||||||||||||||||||||||||||
| 98 | All functions may also be called as class methods and support inheritance too. | ||||||||||||||||||||||||||||
| 99 | See L<http://php.net/manual/en/ref.password.php> for detailed usage instructions. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | use PHP::Functions::Password (); | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Functional interface, typical use: | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | use PHP::Functions::Password qw(password_hash); | ||||||||||||||||||||||||||||
| 108 | my $password = 'secret'; | ||||||||||||||||||||||||||||
| 109 | my $crypted_string = password_hash($password); # uses PASSWORD_BCRYPT algorithm | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Functional interface use, using options: | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | use PHP::Functions::Password qw(:all); | ||||||||||||||||||||||||||||
| 114 | my $password = 'secret'; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # Specify options (see PHP docs for which): | ||||||||||||||||||||||||||||
| 117 | my $crypted_string = password_hash($password, PASSWORD_DEFAULT, cost => 11); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Use a different algorithm: | ||||||||||||||||||||||||||||
| 120 | my $crypted_string = password_hash($password, PASSWORD_ARGON2ID); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Class method use, using options: | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | use PHP::Functions::Password; | ||||||||||||||||||||||||||||
| 125 | my $password = 'secret'; | ||||||||||||||||||||||||||||
| 126 | my $crypted_string = PHP::Functions::Password->hash($password, cost => 9); | ||||||||||||||||||||||||||||
| 127 | # Note that the 2nd argument of password_hash() has been dropped here and may be specified | ||||||||||||||||||||||||||||
| 128 | # as an option as should've been the case in the original password_hash() function IMHO. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 EXPORTS | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | The following names can be imported into the calling namespace by request: | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | password_algos | ||||||||||||||||||||||||||||
| 135 | password_get_info | ||||||||||||||||||||||||||||
| 136 | password_hash | ||||||||||||||||||||||||||||
| 137 | password_needs_rehash | ||||||||||||||||||||||||||||
| 138 | password_verify | ||||||||||||||||||||||||||||
| 139 | PASSWORD_ARGON2I | ||||||||||||||||||||||||||||
| 140 | PASSWORD_ARGON2ID | ||||||||||||||||||||||||||||
| 141 | PASSWORD_BCRYPT | ||||||||||||||||||||||||||||
| 142 | PASSWORD_DEFAULT | ||||||||||||||||||||||||||||
| 143 | :all - what it says | ||||||||||||||||||||||||||||
| 144 | :consts - the PASSWORD_* constants | ||||||||||||||||||||||||||||
| 145 | :funcs - the password_* functions | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 PHP COMPATIBLE AND EXPORTABLE FUNCTIONS | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =over | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item password_algos() | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | The same as L<http://php.net/manual/en/function.password-algos.php> | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Returns an array of supported password algorithm signatures. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | sub password_algos { | ||||||||||||||||||||||||||||
| 160 | 2 | ▶ | my @result = ($SIG_BCRYPT); | ||||||||||||||||||||||||||
|
Subroutine
password_algos: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 2 | ▶ | if ($INC{'Crypt/Argon2.pm'} || eval { require Crypt::Argon2; }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
MC/DC0%0/2
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
$INC{"Crypt/Argon2.pm"}
eval {
do {
require Crypt::Argon2
}
}
Truth table33%1/3
A or B
A= $INC{"Crypt/Argon2.pm"}B= eval {
do {
require Crypt::Argon2
}
}
| |||||||||||||||||||||||||||||
| 162 | 2 | push(@result, $SIG_ARGON2I, $SIG_ARGON2ID); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 2 | return @result; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item password_get_info($crypted) | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | The same as L<http://php.net/manual/en/function.password-get-info.php> | ||||||||||||||||||||||||||||
| 173 | with the exception that it returns the following additional keys in the result: | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | algoSig e.g. '2y' | ||||||||||||||||||||||||||||
| 176 | salt (encoded) | ||||||||||||||||||||||||||||
| 177 | hash (encoded) | ||||||||||||||||||||||||||||
| 178 | version (only for argon2 algorithms) | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Returns a hash in array context, else a hashref. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub password_get_info { | ||||||||||||||||||||||||||||
| 185 | 34 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
password_get_info: called CC=8 SCAR=20.8
Pod
documented
Branch: 1 branch
Condition66%2/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC50%1/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table66%2/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 186 | 34 | my $crypted = shift; | |||||||||||||||||||||||||||
| 187 | 34 | ▶ | if ($crypted =~ $RE_BCRYPT_STRING) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 188 | 18 | my $type = $1; | |||||||||||||||||||||||||||
| 189 | 18 | my $cost = int($2); | |||||||||||||||||||||||||||
| 190 | 18 | my $salt = $3; | |||||||||||||||||||||||||||
| 191 | 18 | my $hash = $4; | |||||||||||||||||||||||||||
| 192 | 18 | my %result = ( | |||||||||||||||||||||||||||
| 193 | 'algo' => PASSWORD_BCRYPT, | ||||||||||||||||||||||||||||
| 194 | 'algoName' => 'bcrypt', | ||||||||||||||||||||||||||||
| 195 | 'options' => { | ||||||||||||||||||||||||||||
| 196 | 'cost' => $cost, | ||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||
| 198 | 'algoSig' => $type, # extra | ||||||||||||||||||||||||||||
| 199 | 'salt' => $salt, # extra | ||||||||||||||||||||||||||||
| 200 | 'hash' => $hash, # extra | ||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||
| 202 | 18 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | elsif ($crypted =~ $RE_ARGON2_STRING) { | ||||||||||||||||||||||||||||
| 205 | 10 | my $sig = $1; | |||||||||||||||||||||||||||
| 206 | 10 | my $version = int($2); | |||||||||||||||||||||||||||
| 207 | 10 | my $memory_cost = int($3); | |||||||||||||||||||||||||||
| 208 | 10 | my $time_cost = int($4); | |||||||||||||||||||||||||||
| 209 | 10 | my $threads = int($5); | |||||||||||||||||||||||||||
| 210 | 10 | my $salt = $6; | |||||||||||||||||||||||||||
| 211 | 10 | my $hash = $7; | |||||||||||||||||||||||||||
| 212 | #my $raw_salt = decode_base64($salt); | ||||||||||||||||||||||||||||
| 213 | #my $raw_hash = decode_base64($hash); | ||||||||||||||||||||||||||||
| 214 | my %result = ( | ||||||||||||||||||||||||||||
| 215 | 10 | 'algo' => $SIG_TO_ALGO{$sig}, | |||||||||||||||||||||||||||
| 216 | 'algoName' => $sig, | ||||||||||||||||||||||||||||
| 217 | 'options' => { | ||||||||||||||||||||||||||||
| 218 | 'memory_cost' => $memory_cost, | ||||||||||||||||||||||||||||
| 219 | 'time_cost' => $time_cost, | ||||||||||||||||||||||||||||
| 220 | 'threads' => $threads, | ||||||||||||||||||||||||||||
| 221 | }, | ||||||||||||||||||||||||||||
| 222 | 'algoSig' => $sig, | ||||||||||||||||||||||||||||
| 223 | 'salt' => $salt, | ||||||||||||||||||||||||||||
| 224 | 'hash' => $hash, | ||||||||||||||||||||||||||||
| 225 | 'version' => $version, | ||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||
| 227 | 10 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # No matches: | ||||||||||||||||||||||||||||
| 231 | 6 | my %result = ( | |||||||||||||||||||||||||||
| 232 | 'algo' => 0, | ||||||||||||||||||||||||||||
| 233 | 'algoName' => 'unknown', | ||||||||||||||||||||||||||||
| 234 | 'options' => {}, | ||||||||||||||||||||||||||||
| 235 | ); | ||||||||||||||||||||||||||||
| 236 | 6 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =item password_hash($password, $algo, %options) | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | Similar to L<http://php.net/manual/en/function.password-hash.php> | ||||||||||||||||||||||||||||
| 245 | with difference that the $algo argument is optional and defaults to PASSWORD_DEFAULT for your programming pleasure. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | Important notes about the 'salt' option which you shouldn't use: | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | - The PASSWORD_BCRYPT 'salt' option is deprecated since PHP 7.0, but if you do pass it, then it must be bcrypt custom base64 encoded and not raw bytes! | ||||||||||||||||||||||||||||
| 250 | - For algorithms other than PASSWORD_BCRYPT, PHP doesn't support the 'salt' option, but if you do pass it, then it must be in raw bytes! | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | sub password_hash { | ||||||||||||||||||||||||||||
| 255 | 41 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
password_hash: called CC=23 SCAR=39.4
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 256 | 41 | my $password = shift; | |||||||||||||||||||||||||||
| 257 | 41 | ▶ | my $algo = shift // PASSWORD_DEFAULT; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 258 | 41 | ▶ | my %options = @_ && ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table66%2/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||
| 259 | 41 | ▶ | if ($algo == PASSWORD_BCRYPT) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 260 | 35 | my $salt; | |||||||||||||||||||||||||||
| 261 | 35 | ▶ | if (defined($options{'salt'}) && length($options{'salt'})) { # bcrypt custom base64 encoded! | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $options{"salt"} and length $options{"salt"}
MC/DC50%1/2
defined $options{"salt"} and length $options{"salt"}
defined $options{"salt"}
length $options{"salt"}
Truth table66%2/3
A and B
A= defined $options{"salt"}B= length $options{"salt"}
| |||||||||||||||||||||||||||||
| 262 | 32 | ▶ | unless ($options{'salt'} =~ /^$RE_BCRYPT_SALT$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | croak('Bad syntax in given and deprecated salt option (' . $options{'salt'} . ')'); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 32 | $salt = $options{'salt'}; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | else { | ||||||||||||||||||||||||||||
| 268 | 3 | $salt = $proto->_bcrypt_base64_encode(Crypt::OpenSSL::Random::random_bytes(16)); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | 35 | ▶ | my $cost = $options{'cost'} || $PASSWORD_BCRYPT_DEFAULT_COST; | ||||||||||||||||||||||||||
|
Condition66%2/3
$options{'cost'} || $PASSWORD_BCRYPT_DEFAULT_COST
MC/DC0%0/2
$options{'cost'} || $PASSWORD_BCRYPT_DEFAULT_COST
$options{'cost'}
$PASSWORD_BCRYPT_DEFAULT_COST
Truth table66%2/3
A || B
A= $options{'cost'}B= $PASSWORD_BCRYPT_DEFAULT_COST
| |||||||||||||||||||||||||||||
| 271 | 35 | my $settings = '$' . $SIG_BCRYPT . '$' . sprintf('%.2u', $cost) . '$' . $salt; | |||||||||||||||||||||||||||
| 272 | 35 | return $proto->_bcrypt($password, $settings); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | ▶ | elsif (($algo == PASSWORD_ARGON2ID) || ($algo == PASSWORD_ARGON2I)) { | |||||||||||||||||||||||||||
|
Condition66%2/3
$algo == 3 or $algo == 2
MC/DC0%0/2
$algo == 3 or $algo == 2
$algo == 3
$algo == 2
Truth table66%2/3
A or B
A= $algo == 3B= $algo == 2
| |||||||||||||||||||||||||||||
| 275 | 6 | ▶ | unless ($INC{'Crypt/Argon2.pm'} || eval { require Crypt::Argon2; }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
MC/DC0%0/2
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
$INC{"Crypt/Argon2.pm"}
eval {
do {
require Crypt::Argon2
}
}
Truth table33%1/3
A or B
A= $INC{"Crypt/Argon2.pm"}B= eval {
do {
require Crypt::Argon2
}
}
| |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my $algo_const_name = $algo == PASSWORD_ARGON2ID ? PASSWORD_ARGON2ID : PASSWORD_ARGON2I; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | croak("Cannot use the $algo_const_name algorithm because the module Crypt::Argon2 is not installed"); | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | 6 | ▶ | my $salt = $options{'salt'} || Crypt::OpenSSL::Random::random_bytes($PASSWORD_ARGON2_DEFAULT_SALT_LENGTH); # undocumented; not a PHP option; raw! | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'salt'} || Crypt::OpenSSL::Random::random_bytes($PASSWORD_ARGON2_DEFAULT_SALT_LENGTH)
MC/DC0%0/2
$options{'salt'} || Crypt::OpenSSL::Random::random_bytes($PASSWORD_ARGON2_DEFAULT_SALT_LENGTH)
$options{'salt'}
Crypt::OpenSSL::Random::random_bytes($PASSWORD_ARGON2_DEFAULT_SALT_LENGTH)
Truth table33%1/3
A || B
A= $options{'salt'}B= Crypt::OpenSSL::Random::random_bytes($PASSWORD_ARGON2_DEFAULT_SALT_LENGTH)
| |||||||||||||||||||||||||||||
| 280 | 6 | ▶ | my $memory_cost = $options{'memory_cost'} || $PASSWORD_ARGON2_DEFAULT_MEMORY_COST; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'memory_cost'} || $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
MC/DC0%0/2
$options{'memory_cost'} || $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
$options{'memory_cost'}
$PASSWORD_ARGON2_DEFAULT_MEMORY_COST
Truth table33%1/3
A || B
A= $options{'memory_cost'}B= $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
| |||||||||||||||||||||||||||||
| 281 | 6 | ▶ | my $time_cost = $options{'time_cost'} || $PASSWORD_ARGON2_DEFAULT_TIME_COST; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'time_cost'} || $PASSWORD_ARGON2_DEFAULT_TIME_COST
MC/DC0%0/2
$options{'time_cost'} || $PASSWORD_ARGON2_DEFAULT_TIME_COST
$options{'time_cost'}
$PASSWORD_ARGON2_DEFAULT_TIME_COST
Truth table33%1/3
A || B
A= $options{'time_cost'}B= $PASSWORD_ARGON2_DEFAULT_TIME_COST
| |||||||||||||||||||||||||||||
| 282 | 6 | ▶ | my $threads = $options{'threads'} || $PASSWORD_ARGON2_DEFAULT_THREADS; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'threads'} || $PASSWORD_ARGON2_DEFAULT_THREADS
MC/DC0%0/2
$options{'threads'} || $PASSWORD_ARGON2_DEFAULT_THREADS
$options{'threads'}
$PASSWORD_ARGON2_DEFAULT_THREADS
Truth table33%1/3
A || B
A= $options{'threads'}B= $PASSWORD_ARGON2_DEFAULT_THREADS
| |||||||||||||||||||||||||||||
| 283 | 6 | ▶ | my $tag_length = $options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH; # undocumented; not a PHP option; 4 - 2^32 - 1 | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
MC/DC0%0/2
$options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
$options{'tag_length'}
$PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
Truth table33%1/3
A || B
A= $options{'tag_length'}B= $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | # Ignore characters and treat strings as strings of bytes | ||||||||||||||||||||||||||||
| 286 | 6 | ▶ | utf8::is_utf8($password) && utf8::encode($password); # "\x{100}" becomes "\xc4\x80"; preferred equivalent of Encode::is_utf8($string) && Encode::_utf8_off($password); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 6 | my @args = ($password, $salt, $time_cost, $memory_cost . 'k', $threads, $tag_length); | |||||||||||||||||||||||||||
| 289 | 6 | ▶ | if ($algo == PASSWORD_ARGON2ID) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 3 | return Crypt::Argon2::argon2id_pass(@args); | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||
| 293 | 3 | return Crypt::Argon2::argon2i_pass(@args); | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | else { | ||||||||||||||||||||||||||||
| 297 | 0 | croak("Unimplemented algorithm $algo"); | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =item password_needs_rehash($crypted, $algo, %options) | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | The same as L<http://php.net/manual/en/function.password-needs-rehash.php>. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | sub password_needs_rehash { | ||||||||||||||||||||||||||||
| 311 | 24 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
password_needs_rehash: called CC=41 SCAR=51.7
Pod
documented
Branch: 1 branch
Condition66%2/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC50%1/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table66%2/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 312 | 24 | my $crypted = shift; | |||||||||||||||||||||||||||
| 313 | 24 | ▶ | my $algo = shift(@_) // PASSWORD_DEFAULT; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ // 1
MC/DC0%0/1
shift @_ // 1
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 314 | 24 | ▶ | my %options = @_ && ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||
| 315 | 24 | my %info = password_get_info($crypted); | |||||||||||||||||||||||||||
| 316 | 24 | ▶ | unless ($info{'algo'} == $algo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 2 | ▶ | $options{'debug'} && warn('Algorithms differ: ' . $info{'algo'} . "<>$algo"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 2 | return 1; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | 22 | ▶ | if ($algo == PASSWORD_BCRYPT) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 321 | 12 | ▶ | if ($info{'algoSig'} ne $SIG_BCRYPT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 4 | ▶ | $options{'debug'} && warn('Algorithm signatures differ: ' . $info{'algoSig'} . ' vs ' . $SIG_BCRYPT); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 4 | return 1; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | 8 | ▶ | my $cost = $options{'cost'} // $PASSWORD_BCRYPT_DEFAULT_COST; | ||||||||||||||||||||||||||
|
Condition66%2/3
$options{"cost"} // $PASSWORD_BCRYPT_DEFAULT_COST
MC/DC0%0/2
$options{"cost"} // $PASSWORD_BCRYPT_DEFAULT_COST
$options{"cost"}
$PASSWORD_BCRYPT_DEFAULT_COST
Truth table66%2/3
A // B
A= $options{"cost"}B= $PASSWORD_BCRYPT_DEFAULT_COST
| |||||||||||||||||||||||||||||
| 326 | 8 | ▶ | unless (defined($info{'options'}->{'cost'}) && ($info{'options'}->{'cost'} == $cost)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $info{"options"}{"cost"} and $info{"options"}{"cost"} == $cost
MC/DC50%1/2
defined $info{"options"}{"cost"} and $info{"options"}{"cost"} == $cost
defined $info{"options"}{"cost"}
$info{"options"}{"cost"} == $cost
Truth table66%2/3
A and B
A= defined $info{"options"}{"cost"}B= $info{"options"}{"cost"} == $cost
| |||||||||||||||||||||||||||||
| 327 | 4 | ▶ | $options{'debug'} && warn('Cost mismatch: ' . $info{'options'}->{'cost'} . "<>$cost"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 4 | return 1; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | ▶ | elsif (($algo == PASSWORD_ARGON2ID) || ($algo == PASSWORD_ARGON2I)) { | |||||||||||||||||||||||||||
|
Condition66%2/3
$algo == 3 or $algo == 2
MC/DC50%1/2
$algo == 3 or $algo == 2
$algo == 3
$algo == 2
Truth table66%2/3
A or B
A= $algo == 3B= $algo == 2
| |||||||||||||||||||||||||||||
| 332 | 8 | ▶ | my $memory_cost = $options{'memory_cost'} // $PASSWORD_ARGON2_DEFAULT_MEMORY_COST; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{"memory_cost"} // $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
MC/DC0%0/2
$options{"memory_cost"} // $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
$options{"memory_cost"}
$PASSWORD_ARGON2_DEFAULT_MEMORY_COST
Truth table33%1/3
A // B
A= $options{"memory_cost"}B= $PASSWORD_ARGON2_DEFAULT_MEMORY_COST
| |||||||||||||||||||||||||||||
| 333 | 8 | ▶ | if ($info{'options'}->{'memory_cost'} != $memory_cost) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 2 | ▶ | $options{'debug'} && warn('memory_cost mismatch: ' . $info{'options'}->{'memory_cost'} . "<>$memory_cost"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 2 | return 1; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 6 | ▶ | my $time_cost = $options{'time_cost'} // $PASSWORD_ARGON2_DEFAULT_TIME_COST; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{"time_cost"} // $PASSWORD_ARGON2_DEFAULT_TIME_COST
MC/DC0%0/2
$options{"time_cost"} // $PASSWORD_ARGON2_DEFAULT_TIME_COST
$options{"time_cost"}
$PASSWORD_ARGON2_DEFAULT_TIME_COST
Truth table33%1/3
A // B
A= $options{"time_cost"}B= $PASSWORD_ARGON2_DEFAULT_TIME_COST
| |||||||||||||||||||||||||||||
| 338 | 6 | ▶ | if ($info{'options'}->{'time_cost'} != $time_cost) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 2 | ▶ | $options{'debug'} && warn('time_cost mismatch: ' . $info{'options'}->{'time_cost'} . "<>$time_cost"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 2 | return 1; | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | 4 | ▶ | my $threads = $options{'threads'} // $PASSWORD_ARGON2_DEFAULT_THREADS; | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{"threads"} // $PASSWORD_ARGON2_DEFAULT_THREADS
MC/DC0%0/2
$options{"threads"} // $PASSWORD_ARGON2_DEFAULT_THREADS
$options{"threads"}
$PASSWORD_ARGON2_DEFAULT_THREADS
Truth table33%1/3
A // B
A= $options{"threads"}B= $PASSWORD_ARGON2_DEFAULT_THREADS
| |||||||||||||||||||||||||||||
| 343 | 4 | ▶ | if ($info{'options'}->{'threads'} != $threads) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 2 | ▶ | $options{'debug'} && warn('threads mismatch: ' . $info{'options'}->{'threads'} . "<>$threads"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 2 | return 1; | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | 2 | ▶ | my $wanted_salt_length = defined($options{'salt'}) && length($options{'salt'}) ? length($options{'salt'}) : $PASSWORD_ARGON2_DEFAULT_SALT_LENGTH; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options{"salt"} and length $options{"salt"}
MC/DC0%0/2
defined $options{"salt"} and length $options{"salt"}
defined $options{"salt"}
length $options{"salt"}
Truth table33%1/3
A and B
A= defined $options{"salt"}B= length $options{"salt"}
| |||||||||||||||||||||||||||||
| 348 | 2 | ▶ | my $wanted_tag_length = $options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH; # undocumented; not a PHP option; 4 - 2^32 - 1 | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
MC/DC0%0/2
$options{'tag_length'} || $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
$options{'tag_length'}
$PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
Truth table33%1/3
A || B
A= $options{'tag_length'}B= $PASSWORD_ARGON2_DEFAULT_TAG_LENGTH
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 2 | ▶ | if ($INC{'Crypt/Argon2.pm'} || eval { require Crypt::Argon2; }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
MC/DC0%0/2
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
$INC{"Crypt/Argon2.pm"}
eval {
do {
require Crypt::Argon2
}
}
Truth table66%2/3
A or B
A= $INC{"Crypt/Argon2.pm"}B= eval {
do {
require Crypt::Argon2
}
}
| |||||||||||||||||||||||||||||
| 351 | 2 | ▶ | if (version->parse($Crypt::Argon2::VERSION) < version->parse('0.008')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if ($info{'version'} < 19) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | $options{'debug'} && warn('Version mismatch: ' . $info{'version'} . '<19'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 0 | return 1; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | 0 | my $salt_encoded = $info{'salt'}; | |||||||||||||||||||||||||||
| 357 | 0 | my $salt = decode_base64($salt_encoded); | |||||||||||||||||||||||||||
| 358 | 0 | ▶ | if (!defined($salt)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $options{'debug'} && warn("decode_base64('$salt_encoded') failed"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 0 | return 1; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 0 | my $actual_salt_length = length($salt); | |||||||||||||||||||||||||||
| 363 | 0 | ▶ | if ($wanted_salt_length != $actual_salt_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 0 | ▶ | $options{'debug'} && warn("wanted salt length ($wanted_salt_length) != actual salt length ($actual_salt_length)"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 0 | return 1; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 0 | my $tag_encoded = $info{'hash'}; | |||||||||||||||||||||||||||
| 368 | 0 | my $tag = decode_base64($tag_encoded); | |||||||||||||||||||||||||||
| 369 | 0 | my $actual_tag_length = length($tag); | |||||||||||||||||||||||||||
| 370 | 0 | ▶ | if ($wanted_tag_length != $actual_tag_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $options{'debug'} && warn("wanted tag length ($wanted_tag_length) != actual tag length ($actual_tag_length)"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 0 | return 1; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||||||||||
| 376 | 2 | return Crypt::Argon2::argon2_needs_rehash($crypted, $info{'algoSig'}, $time_cost, $memory_cost . 'k', $threads, $wanted_tag_length, $wanted_salt_length); | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | else { | ||||||||||||||||||||||||||||
| 381 | 2 | ▶ | $options{'debug'} && warn("Can't do anything with unknown algorithm: $algo"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | 6 | return 0; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =item password_verify($password, $crypted) | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | The same as L<http://php.net/manual/en/function.password-verify.php>. | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | sub password_verify { | ||||||||||||||||||||||||||||
| 396 | 50 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
password_verify: called CC=11 SCAR=24.4
Pod
documented
Branch: 1 branch
Condition66%2/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC50%1/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table66%2/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 397 | 50 | my ($password, $crypted) = @_; | |||||||||||||||||||||||||||
| 398 | 50 | ▶ | if ($crypted =~ $RE_BCRYPT_STRING) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 399 | 32 | my $cost = int($2); | |||||||||||||||||||||||||||
| 400 | 32 | my $salt = $3; | |||||||||||||||||||||||||||
| 401 | 32 | my $hash = $4; | |||||||||||||||||||||||||||
| 402 | 32 | my $new_crypt = $proto->hash( | |||||||||||||||||||||||||||
| 403 | $password, | ||||||||||||||||||||||||||||
| 404 | 'cost' => $cost, | ||||||||||||||||||||||||||||
| 405 | 'salt' => $salt, | ||||||||||||||||||||||||||||
| 406 | ); | ||||||||||||||||||||||||||||
| 407 | 32 | ▶ | if ($crypted eq $new_crypt) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 20 | return 1; | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | # Since the signature may vary slightly, try comparing only the hash. | ||||||||||||||||||||||||||||
| 411 | 12 | ▶ | return ($new_crypt =~ $RE_BCRYPT_STRING) && ($4 eq $hash); | ||||||||||||||||||||||||||
|
Condition66%2/3
$new_crypt =~ /$RE_BCRYPT_STRING/ && $4 eq $hash
MC/DC50%1/2
$new_crypt =~ /$RE_BCRYPT_STRING/ && $4 eq $hash
$new_crypt =~ /$RE_BCRYPT_STRING/
$4 eq $hash
Truth table66%2/3
A && B
A= $new_crypt =~ /$RE_BCRYPT_STRING/B= $4 eq $hash
| |||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | elsif ($crypted =~ $RE_ARGON2_STRING) { | ||||||||||||||||||||||||||||
| 414 | 16 | ▶ | unless ($INC{'Crypt/Argon2.pm'} || eval { require Crypt::Argon2; }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
MC/DC0%0/2
$INC{"Crypt/Argon2.pm"} or eval {
do {
require Crypt::Argon2
}
}
$INC{"Crypt/Argon2.pm"}
eval {
do {
require Crypt::Argon2
}
}
Truth table33%1/3
A or B
A= $INC{"Crypt/Argon2.pm"}B= eval {
do {
require Crypt::Argon2
}
}
| |||||||||||||||||||||||||||||
| 415 | #carp("Verifying the $sig algorithm requires the module Crypt::Argon2 to be installed"); | ||||||||||||||||||||||||||||
| 416 | 0 | return 0; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | 16 | my $algo = $SIG_TO_ALGO{$1}; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | # Ignore characters and treat strings as strings of bytes | ||||||||||||||||||||||||||||
| 421 | 16 | ▶ | utf8::is_utf8($password) && utf8::encode($password); # "\x{100}" becomes "\xc4\x80"; preferred equivalent of Encode::is_utf8($string) && Encode::_utf8_off($password); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 16 | my @args = ($crypted, $password); | |||||||||||||||||||||||||||
| 424 | 16 | ▶ | if ($algo == PASSWORD_ARGON2ID) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 8 | return Crypt::Argon2::argon2id_verify(@args); | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | else { | ||||||||||||||||||||||||||||
| 428 | 8 | return Crypt::Argon2::argon2i_verify(@args); | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | #carp('Bad crypted argument'); | ||||||||||||||||||||||||||||
| 432 | 2 | return 0; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =back | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =head1 SHORTENED ALIAS METHODS | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | =over | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | =item algos() | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | Alias of C<password_algos()>. | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | =cut | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | sub algos { | ||||||||||||||||||||||||||||
| 451 | 1 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
algos: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 452 | 1 | return $proto->password_algos(@_); | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | =item get_info($crypted) | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | Alias of C<password_get_info($crypted)>. | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | =cut | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | sub get_info { | ||||||||||||||||||||||||||||
| 466 | 5 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
get_info: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 467 | 5 | return $proto->password_get_info(@_); | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | =item hash($password, %options) | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | Proxy method for C<password_hash($password, $algo, %options)>. | ||||||||||||||||||||||||||||
| 476 | The difference is that this method does have an $algo argument, | ||||||||||||||||||||||||||||
| 477 | but instead allows the algorithm to be specified with the 'algo' option (in %options). | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | =cut | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | sub hash { | ||||||||||||||||||||||||||||
| 482 | 41 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
hash: called CC=6 SCAR=20.5
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 483 | 41 | my $password = shift; | |||||||||||||||||||||||||||
| 484 | 41 | ▶ | my %options = @_ && ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||
| 485 | 41 | ▶ | my $algo = $options{'algo'} || PASSWORD_DEFAULT; | ||||||||||||||||||||||||||
|
Condition100%2/2
$options{'algo'} || 1
MC/DC100%1/1
$options{'algo'} || 1
$options{'algo'}
Truth table100%2/2
A
A= $options{'algo'}
| |||||||||||||||||||||||||||||
| 486 | 41 | delete($options{'algo'}); | |||||||||||||||||||||||||||
| 487 | 41 | return $proto->password_hash($password, $algo, %options); | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | =item needs_rehash($crypted, $algo, %options) | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | Alias of C<password_needs_rehash($crypted, $algo, %options)>. | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | =cut | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | sub needs_rehash { | ||||||||||||||||||||||||||||
| 500 | 12 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
needs_rehash: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 501 | 12 | return $proto->password_needs_rehash(@_); | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | =item verify($password, $crypted) | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | Alias of C<verify($password, $crypted)>. | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | =cut | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | sub verify { | ||||||||||||||||||||||||||||
| 514 | 25 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 515 | 25 | return $proto->password_verify(@_); | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | =back | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | =cut | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | # From Crypt::Eksblowfish::Bcrypt. | ||||||||||||||||||||||||||||
| 526 | # This is a version of C<crypt> (see L<perlfunc/crypt>) that implements the bcrypt algorithm. | ||||||||||||||||||||||||||||
| 527 | sub _bcrypt { | ||||||||||||||||||||||||||||
| 528 | 35 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
_bcrypt: called CC=4 SCAR=15.5
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 529 | 35 | my ($password, $settings) = @_; | |||||||||||||||||||||||||||
| 530 | 35 | ▶ | unless ($settings =~ qr/^ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | \$ | ||||||||||||||||||||||||||||
| 532 | ($RE_BCRYPT_ALGO) | ||||||||||||||||||||||||||||
| 533 | \$ | ||||||||||||||||||||||||||||
| 534 | ($RE_BCRYPT_COST) | ||||||||||||||||||||||||||||
| 535 | \$ | ||||||||||||||||||||||||||||
| 536 | ($RE_BCRYPT_SALT) | ||||||||||||||||||||||||||||
| 537 | /x) { | ||||||||||||||||||||||||||||
| 538 | 0 | croak('Bad bcrypt settings argument'); | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | 35 | my ($type, $cost, $salt_base64) = ($1, $2, $3); | |||||||||||||||||||||||||||
| 541 | 35 | my $hash = $proto->_bcrypt_hash( | |||||||||||||||||||||||||||
| 542 | $password, | ||||||||||||||||||||||||||||
| 543 | { | ||||||||||||||||||||||||||||
| 544 | 'key_nul' => length($type) > 1, | ||||||||||||||||||||||||||||
| 545 | 'cost' => $cost, | ||||||||||||||||||||||||||||
| 546 | 'salt' => $proto->_bcrypt_base64_decode($salt_base64), | ||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | ); | ||||||||||||||||||||||||||||
| 549 | 35 | return '$' . $SIG_BCRYPT . '$' . $cost . '$' . $salt_base64 . $proto->_bcrypt_base64_encode($hash); | |||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | # From Crypt::Eksblowfish::Bcrypt. | ||||||||||||||||||||||||||||
| 556 | # Hashes $password according to the supplied $settings, and returns the 23-octet hash. | ||||||||||||||||||||||||||||
| 557 | sub _bcrypt_hash { | ||||||||||||||||||||||||||||
| 558 | 35 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
_bcrypt_hash: called CC=7 SCAR=20.2
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 559 | 35 | my ($password, $settings) = @_; | |||||||||||||||||||||||||||
| 560 | 35 | ▶ | if ($settings->{'key_nul'} || ($password eq '')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$settings->{"key_nul"} or $password eq ""
MC/DC0%0/2
$settings->{"key_nul"} or $password eq ""
$settings->{"key_nul"}
$password eq ""
Truth table33%1/3
A or B
A= $settings->{"key_nul"}B= $password eq ""
| |||||||||||||||||||||||||||||
| 561 | 35 | $password .= "\0"; | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | # Ignore characters and treat strings as strings of bytes | ||||||||||||||||||||||||||||
| 565 | 35 | ▶ | utf8::is_utf8($password) && utf8::encode($password); # "\x{100}" becomes "\xc4\x80"; preferred equivalent of Encode::is_utf8($string) && Encode::_utf8_off($password); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | my $cipher = Crypt::Eksblowfish->new( | ||||||||||||||||||||||||||||
| 568 | $settings->{'cost'}, | ||||||||||||||||||||||||||||
| 569 | 35 | $settings->{'salt'}, | |||||||||||||||||||||||||||
| 570 | substr($password, 0, 72) | ||||||||||||||||||||||||||||
| 571 | ); | ||||||||||||||||||||||||||||
| 572 | my $hash = join('', | ||||||||||||||||||||||||||||
| 573 | map { | ||||||||||||||||||||||||||||
| 574 | 35 | my $blk = $_; | |||||||||||||||||||||||||||
| 575 | 105 | ▶ | for(my $i = 64; $i--; ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | 6720 | $blk = $cipher->encrypt($blk); | |||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | 105 | $blk; | |||||||||||||||||||||||||||
| 579 | } qw(OrpheanB eholderS cryDoubt) | ||||||||||||||||||||||||||||
| 580 | ); | ||||||||||||||||||||||||||||
| 581 | 35 | chop($hash); | |||||||||||||||||||||||||||
| 582 | 35 | return $hash; | |||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | # From Crypt::Eksblowfish::Bcrypt. | ||||||||||||||||||||||||||||
| 589 | # Decodes an octet string that was textually encoded using the form of base64 that is conventionally used with bcrypt. | ||||||||||||||||||||||||||||
| 590 | sub _bcrypt_base64_decode { | ||||||||||||||||||||||||||||
| 591 | 35 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
_bcrypt_base64_decode: called CC=4 SCAR=15.5
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 592 | 35 | my $text = shift; | |||||||||||||||||||||||||||
| 593 | 35 | ▶ | unless ($text =~ m!\A(?>(?:[./A-Za-z0-9]{4})*)(?:|[./A-Za-z0-9]{2}[.CGKOSWaeimquy26]|[./A-Za-z0-9][.Oeu])\z!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 594 | 0 | croak('Bad base64 encoded text argument'); | |||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | 35 | $text =~ tr#./A-Za-z0-9#A-Za-z0-9+/#; | |||||||||||||||||||||||||||
| 597 | 35 | $text .= '=' x (3 - (length($text) + 3) % 4); | |||||||||||||||||||||||||||
| 598 | 35 | return decode_base64($text); | |||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | # From Crypt::Eksblowfish::Bcrypt. | ||||||||||||||||||||||||||||
| 605 | # Encodes the octet string textually using the form of base64 that is conventionally used with bcrypt. | ||||||||||||||||||||||||||||
| 606 | sub _bcrypt_base64_encode { | ||||||||||||||||||||||||||||
| 607 | 38 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
_bcrypt_base64_encode: called CC=3 SCAR=11.8
Branch: 1 branch
Condition33%1/3
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
MC/DC0%0/2
@_ and UNIVERSAL::isa($_[0], __PACKAGE__)
@_
UNIVERSAL::isa($_[0], __PACKAGE__)
Truth table33%1/3
A and B
A= @_B= UNIVERSAL::isa($_[0], __PACKAGE__)
| |||||||||||||||||||||||||||||
| 608 | 38 | my $octets = shift; | |||||||||||||||||||||||||||
| 609 | 38 | my $text = encode_base64($octets, ''); | |||||||||||||||||||||||||||
| 610 | 38 | $text =~ tr#A-Za-z0-9+/=#./A-Za-z0-9#d; # "=" padding is deleted | |||||||||||||||||||||||||||
| 611 | 38 | return $text; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 6 | 1; | |||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | __END__ | ||||||||||||||||||||||||||||