| 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::Bcrypt (); | ||||||||||||||||||||||||||||||||||||||||
|
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(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 base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | our @EXPORT; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 13 | password_algos | ||||||||||||||||||||||||||||||||||||||||||
| 14 | password_get_info | ||||||||||||||||||||||||||||||||||||||||||
| 15 | password_hash | ||||||||||||||||||||||||||||||||||||||||||
| 16 | password_needs_rehash | ||||||||||||||||||||||||||||||||||||||||||
| 17 | password_verify | ||||||||||||||||||||||||||||||||||||||||||
| 18 | PASSWORD_BCRYPT | ||||||||||||||||||||||||||||||||||||||||||
| 19 | PASSWORD_ARGON2I | ||||||||||||||||||||||||||||||||||||||||||
| 20 | PASSWORD_ARGON2ID | ||||||||||||||||||||||||||||||||||||||||||
| 21 | PASSWORD_DEFAULT | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | 'all' => \@EXPORT_OK, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 'default' => \@EXPORT, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 'consts' => [ grep /^PASSWORD_/, @EXPORT_OK ], | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'funcs' => [ grep /^password_/, @EXPORT_OK ], | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | our $VERSION = '1.13'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Exported constants | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use constant PASSWORD_BCRYPT => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | use constant PASSWORD_ARGON2I => 2; # exists in PHP since version 7.2 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | use constant PASSWORD_ARGON2ID => 3; # exists in PHP since version 7.3 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use constant PASSWORD_DEFAULT => PASSWORD_BCRYPT; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # Internal constants | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | Readonly my $PASSWORD_BCRYPT_DEFAULT_COST => 10; # no such PHP constant | |||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | Readonly my $PASSWORD_BCRYPT_MAX_PASSWORD_LEN => 72; # 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; equivalent of 2b in non-PHP implementations | |||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | Readonly my $SIG_ARGON2I => 'argon2i'; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | Readonly my $SIG_ARGON2ID => 'argon2id'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | Readonly my %SIG_TO_ALGO => ( # not used for bcrypt | |||||||||||||||||||||||||||||||||||||||||
| 53 | $SIG_ARGON2I => PASSWORD_ARGON2I, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | $SIG_ARGON2ID => PASSWORD_ARGON2ID, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # https://en.wikipedia.org/wiki/Bcrypt | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | Readonly my $RE_BCRYPT_ALGO => qr#2[abxy]?#; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | Readonly my $RE_BCRYPT_SALT => qr#[./A-Za-z0-9]{22}#; # fixed 16 byte salt (encoded as 22 bcrypt-custom-base64 chars) | |||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | Readonly my $RE_BCRYPT_COST => qr#[0-3]\d#; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | Readonly my $RE_BCRYPT_HASH => qr#[./A-Za-z0-9]+#; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | Readonly my $RE_BCRYPT_STRING => qr/^ | |||||||||||||||||||||||||||||||||||||||||
| 63 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ($RE_BCRYPT_ALGO) # $1 type | ||||||||||||||||||||||||||||||||||||||||||
| 65 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ($RE_BCRYPT_COST) # $2 cost | ||||||||||||||||||||||||||||||||||||||||||
| 67 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ($RE_BCRYPT_SALT) # $3 salt | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ($RE_BCRYPT_HASH) # $4 hash | ||||||||||||||||||||||||||||||||||||||||||
| 70 | $/x; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # See https://www.alexedwards.net/blog/how-to-hash-and-verify-passwords-with-argon2-in-go | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | Readonly my $RE_ARGON2_ALGO => qr#argon2id?#; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | Readonly my $RE_ARGON2_STRING => qr/^ | |||||||||||||||||||||||||||||||||||||||||
| 75 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ($RE_ARGON2_ALGO) # $1 signature | ||||||||||||||||||||||||||||||||||||||||||
| 77 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 78 | v=(\d{1,3}) # $2 version | ||||||||||||||||||||||||||||||||||||||||||
| 79 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 80 | m=(\d{1,10}), # $3 memory_cost | ||||||||||||||||||||||||||||||||||||||||||
| 81 | t=(\d{1,3}), # $4 time_cost | ||||||||||||||||||||||||||||||||||||||||||
| 82 | p=(\d{1,3}) # $5 threads | ||||||||||||||||||||||||||||||||||||||||||
| 83 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ([A-Za-z0-9+\/]+) # $6 salt | ||||||||||||||||||||||||||||||||||||||||||
| 85 | \$ | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ([A-Za-z0-9+\/]+) # $7 hash | ||||||||||||||||||||||||||||||||||||||||||
| 87 | $/x; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | PHP::Functions::Password - Perl ports of PHP password functions | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | This module provides ported PHP password functions. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | This module supports the bcrypt, argon2i, and argon2id algorithms, as is the case with the equivalent PHP functions at the date of writing this. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | All functions may also be called as class methods and support inheritance too. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | See L<http://php.net/manual/en/ref.password.php> for detailed usage instructions. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | use PHP::Functions::Password (); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | Functional interface, typical use: | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | use PHP::Functions::Password qw(password_hash); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | my $password = 'secret'; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | my $crypted_string = password_hash($password); # uses PASSWORD_BCRYPT algorithm | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | Functional interface use, using options: | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | use PHP::Functions::Password qw(:all); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | my $password = 'secret'; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # Specify options (see PHP docs for which): | ||||||||||||||||||||||||||||||||||||||||||
| 116 | my $crypted_string = password_hash($password, PASSWORD_DEFAULT, cost => 11); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # Use a different algorithm: | ||||||||||||||||||||||||||||||||||||||||||
| 119 | my $crypted_string = password_hash($password, PASSWORD_ARGON2ID); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # Better practice using a 'pepper': | ||||||||||||||||||||||||||||||||||||||||||
| 122 | use Digest::SHA qw(hmac_sha256); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | my $pepper = 'Abracadabra and Hocus pocus'; # retrieve this from a secrets config file for example (and don't loose it!) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | my $peppered_password = hmac_sha256($password, $pepper); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | my $crypted_string = password_hash($password, PASSWORD_ARGON2ID); # store this in your database | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # ... and when verifying passwords, then you pepper then first too. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | Class method use, using options: | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | use PHP::Functions::Password; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | my $password = 'secret'; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | my $crypted_string = PHP::Functions::Password->hash($password, cost => 9); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # Note that the 2nd argument of password_hash() has been dropped here and may be specified | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # as an option as should've been the case in the original password_hash() function IMHO. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 EXPORTS | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | The following names can be imported into the calling namespace by request: | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | password_algos | ||||||||||||||||||||||||||||||||||||||||||
| 141 | password_get_info | ||||||||||||||||||||||||||||||||||||||||||
| 142 | password_hash | ||||||||||||||||||||||||||||||||||||||||||
| 143 | password_needs_rehash | ||||||||||||||||||||||||||||||||||||||||||
| 144 | password_verify | ||||||||||||||||||||||||||||||||||||||||||
| 145 | PASSWORD_ARGON2I | ||||||||||||||||||||||||||||||||||||||||||
| 146 | PASSWORD_ARGON2ID | ||||||||||||||||||||||||||||||||||||||||||
| 147 | PASSWORD_BCRYPT | ||||||||||||||||||||||||||||||||||||||||||
| 148 | PASSWORD_DEFAULT | ||||||||||||||||||||||||||||||||||||||||||
| 149 | :all - what it says | ||||||||||||||||||||||||||||||||||||||||||
| 150 | :consts - the PASSWORD_* constants | ||||||||||||||||||||||||||||||||||||||||||
| 151 | :funcs - the password_* functions | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 PHP COMPATIBLE AND EXPORTABLE FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =item password_algos() | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | The same as L<http://php.net/manual/en/function.password-algos.php> | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Returns an array of supported password algorithm signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | sub password_algos { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | my @result = ($SIG_BCRYPT); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
password_algos: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 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
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | push(@result, $SIG_ARGON2I, $SIG_ARGON2ID); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =item password_get_info($crypted) | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | The same as L<http://php.net/manual/en/function.password-get-info.php> | ||||||||||||||||||||||||||||||||||||||||||
| 179 | with the exception that it returns the following additional keys in the result: | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | algoSig e.g. '2y' | ||||||||||||||||||||||||||||||||||||||||||
| 182 | salt (encoded) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | hash (encoded) | ||||||||||||||||||||||||||||||||||||||||||
| 184 | version (only for argon2 algorithms) | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | Returns a hash in array context, else a hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | sub password_get_info { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 34 | my $crypted = shift; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 34 | ▶ | if ($crypted =~ $RE_BCRYPT_STRING) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 18 | my $type = $1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 18 | my $cost = int($2); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 18 | my $salt = $3; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 18 | my $hash = $4; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | my %result = ( | |||||||||||||||||||||||||||||||||||||||||
| 199 | 'algo' => PASSWORD_BCRYPT, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 'algoName' => 'bcrypt', | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 'algoSig' => $type, # extra | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 'options' => { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 'cost'=> $cost, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 'salt' => $salt, # extra | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 'hash' => $hash, # extra | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 18 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | elsif ($crypted =~ $RE_ARGON2_STRING) { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | my $sig = $1; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | my $version = int($2); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 10 | my $memory_cost = int($3); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 10 | my $time_cost = int($4); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 10 | my $threads = int($5); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 10 | my $salt = $6; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 10 | my $hash = $7; | |||||||||||||||||||||||||||||||||||||||||
| 218 | #my $raw_salt = decode_base64($salt); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | #my $raw_hash = decode_base64($hash); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | my %result = ( | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 10 | 'algo' => $SIG_TO_ALGO{$sig}, | |||||||||||||||||||||||||||||||||||||||||
| 222 | 'algoName' => $sig, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 'algoSig' => $sig, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 'options' => { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 'memory_cost' => $memory_cost, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 'time_cost' => $time_cost, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 'threads' => $threads, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 'salt' => $salt, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 'hash' => $hash, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 'version' => $version, | ||||||||||||||||||||||||||||||||||||||||||
| 232 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 10 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # No matches: | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | my %result = ( | |||||||||||||||||||||||||||||||||||||||||
| 238 | 'algo' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 'algoName' => 'unknown', | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 'options' => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 6 | ▶ | return wantarray ? %result : \%result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =item password_hash($password, $algo, %options) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | Similar to L<http://php.net/manual/en/function.password-hash.php> with the difference that the $algo argument is optional and defaults to PASSWORD_DEFAULT for your programming pleasure. | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | Important notes about the 'salt' option which you shouldn't use in the first place: | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | - The PASSWORD_BCRYPT 'salt' option is deprecated since PHP 7.0, but if you do pass it, then it must be 16 bytes long! | ||||||||||||||||||||||||||||||||||||||||||
| 255 | - 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! | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | sub password_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 9 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
password_hash: called CC=31 SCAR=51.2
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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 9 | my $password = shift; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 9 | ▶ | my $algo = shift // PASSWORD_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 9 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | ▶ | unless ($algo =~ /^\d$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | croak("Invalid \$algo parameter ($algo) which should be one of the PASSWORD_* integer constants"); | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 9 | ▶ | if ($algo == PASSWORD_BCRYPT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my $salt; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | ▶ | if (defined($options{'salt'}) && length($options{'salt'})) { | ||||||||||||||||||||||||||||||||||||||||
|
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | # Treat salt as a string of bytes | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $salt = $options{'salt'}; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | utf8::is_utf8($salt) && utf8::encode($salt); # "\x{100}" becomes "\xc4\x80"; preferred equivalent of Encode::is_utf8($string) && Encode::_utf8_off($password); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if (length($salt) == 16) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | # raw bytes: OK | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | elsif ($salt =~ /^$RE_BCRYPT_SALT$/) { # bcrypt-custom-base64 encoded string of 22 characters; DEPRECATED | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $salt =~ tr#./A-Za-z0-9#A-Za-z0-9+/#; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $salt .= '=' x (3 - (length($salt) + 3) % 4); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $salt = decode_base64($salt); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | croak('Bad syntax in given and deprecated salt option (' . $options{'salt'} . ')'); | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | $salt = Crypt::OpenSSL::Random::random_bytes(16); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | my $cost = $PASSWORD_BCRYPT_DEFAULT_COST; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | ▶ | if ($options{'cost'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $min_cost = 5; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $max_cost = 31; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | unless (($options{'cost'} =~ /^\d{1,2}$/) && ($options{'cost'} >= $min_cost) && ($options{'cost'} <= $max_cost)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$options{"cost"} =~ /^\d{1,2}$/ and $options{"cost"} >= $min_cost and $options{"cost"} <= $max_cost
$options{"cost"} =~ /^\d{1,2}$/ and $options{"cost"} >= $min_cost
MC/DC0%0/3
$options{"cost"} =~ /^\d{1,2}$/ and $options{"cost"} >= $min_cost and $options{"cost"} <= $max_cost
$options{"cost"} =~ /^\d{1,2}$/
$options{"cost"} >= $min_cost
$options{"cost"} <= $max_cost
Truth table0%0/4
A and B and C
A= $options{"cost"} =~ /^\d{1,2}$/B= $options{"cost"} >= $min_costC= $options{"cost"} <= $max_cost
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | croak('Invalid cost option given (' . $options{'cost'} . ") which should be an integer in the range $min_cost to $max_cost"); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $cost = int($options{'cost'}); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # Treat passwords as strings of bytes | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 3 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | # Everything beyond the max password length in bytes for bcrypt is silently ignored. | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | require bytes; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | ▶ | if (bytes::length($password) > $PASSWORD_BCRYPT_MAX_PASSWORD_LEN) { # $password is already bytes, so the bytes:: prefix is redundant here | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $password = substr($password, 0, $PASSWORD_BCRYPT_MAX_PASSWORD_LEN); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 3 | return Crypt::Bcrypt::bcrypt($password, $SIG_BCRYPT, $cost, $salt); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 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
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | my $algo_const_name = $algo == PASSWORD_ARGON2ID ? PASSWORD_ARGON2ID : PASSWORD_ARGON2I; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | croak("Cannot use the $algo_const_name algorithm because the module Crypt::Argon2 is not installed"); | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 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)
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # Treat passwords as strings of bytes | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 6 | my @args = ($password, $salt, $time_cost, $memory_cost . 'k', $threads, $tag_length); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 6 | ▶ | if ($algo == PASSWORD_ARGON2ID) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | return Crypt::Argon2::argon2id_pass(@args); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 3 | return Crypt::Argon2::argon2i_pass(@args); | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | croak("Unimplemented algorithm $algo"); | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | =item password_needs_rehash($crypted, $algo, %options) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | The same as L<http://php.net/manual/en/function.password-needs-rehash.php>. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | sub password_needs_rehash { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 24 | my $crypted = shift; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 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 @_
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 24 | my %info = password_get_info($crypted); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 24 | ▶ | unless ($info{'algo'} == $algo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | $options{'debug'} && warn('Algorithms differ: ' . $info{'algo'} . "<>$algo"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 22 | ▶ | if ($algo == PASSWORD_BCRYPT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | #unless (($info{'algoSig'} eq $SIG_BCRYPT) || ($info{'algoSig'} eq '2b')) { # also accept 2b as a non-PHP equivalent of 2y | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 12 | ▶ | unless ($info{'algoSig'} eq $SIG_BCRYPT) { # this emulates PHP's behaviour (it requires 2b to be rehashed as 2y). | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 4 | ▶ | $options{'debug'} && warn('Algorithm signatures differ: ' . $info{'algoSig'} . ' vs ' . $SIG_BCRYPT); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | ▶ | $options{'debug'} && warn('Cost mismatch: ' . $info{'options'}->{'cost'} . "<>$cost"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | if ($info{'options'}->{'memory_cost'} != $memory_cost) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | ▶ | $options{'debug'} && warn('memory_cost mismatch: ' . $info{'options'}->{'memory_cost'} . "<>$memory_cost"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 6 | ▶ | if ($info{'options'}->{'time_cost'} != $time_cost) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | ▶ | $options{'debug'} && warn('time_cost mismatch: ' . $info{'options'}->{'time_cost'} . "<>$time_cost"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | if ($info{'options'}->{'threads'} != $threads) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | ▶ | $options{'debug'} && warn('threads mismatch: ' . $info{'options'}->{'threads'} . "<>$threads"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 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
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | ▶ | if (Crypt::Argon2->can('argon2_needs_rehash')) { # since version 0.008 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | return Crypt::Argon2::argon2_needs_rehash($crypted, $info{'algoSig'}, $time_cost, $memory_cost . 'k', $threads, $wanted_tag_length, $wanted_salt_length); | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | else { # as long as Crypt::Argon2 is not required for building, a minimum version requirement cannot be forced, and therefore the workaround below is needed | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if ($info{'version'} < 19) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $options{'debug'} && warn('Version mismatch: ' . $info{'version'} . '<19'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $salt_encoded = $info{'salt'}; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $salt = decode_base64($salt_encoded); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if (!defined($salt)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | $options{'debug'} && warn("decode_base64('$salt_encoded') failed"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $actual_salt_length = length($salt); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ($wanted_salt_length != $actual_salt_length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $options{'debug'} && warn("wanted salt length ($wanted_salt_length) != actual salt length ($actual_salt_length)"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $tag_encoded = $info{'hash'}; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $tag = decode_base64($tag_encoded); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $actual_tag_length = length($tag); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ($wanted_tag_length != $actual_tag_length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $options{'debug'} && warn("wanted tag length ($wanted_tag_length) != actual tag length ($actual_tag_length)"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | ▶ | $options{'debug'} && warn("Can't do anything with unknown algorithm: $algo"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 6 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | =item password_verify($password, $crypted) | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | The same as L<http://php.net/manual/en/function.password-verify.php>. | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | sub password_verify { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 50 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
password_verify: called CC=11 SCAR=24.3
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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 50 | my ($password, $crypted) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 50 | ▶ | if ($crypted =~ $RE_BCRYPT_STRING) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # Treat passwords as strings of bytes | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 32 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | # Everything beyond the max password length in bytes for bcrypt is silently ignored. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 32 | require bytes; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 32 | ▶ | if (bytes::length($password) > $PASSWORD_BCRYPT_MAX_PASSWORD_LEN) { # $password is already bytes, so the bytes:: prefix is redundant here | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 10 | $password = substr($password, 0, $PASSWORD_BCRYPT_MAX_PASSWORD_LEN); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 32 | return Crypt::Bcrypt::bcrypt_check($password, $crypted); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | elsif ($crypted =~ $RE_ARGON2_STRING) { | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 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
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | #carp("Verifying the $sig algorithm requires the module Crypt::Argon2 to be installed"); | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 16 | my $algo = $SIG_TO_ALGO{$1}; | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | # Treat passwords as strings of bytes | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 16 | my @args = ($crypted, $password); | |||||||||||||||||||||||||||||||||||||||||
| 458 | 16 | ▶ | if ($algo == PASSWORD_ARGON2ID) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | return Crypt::Argon2::argon2id_verify(@args); | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 8 | return Crypt::Argon2::argon2i_verify(@args); | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | #carp('Bad crypted argument'); | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =head1 SHORTENED ALIAS METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =item algos() | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | Alias of C<password_algos()>. | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | sub algos { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | return $proto->password_algos(@_); | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | =item get_info($crypted) | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | Alias of C<password_get_info($crypted)>. | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | sub get_info { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 5 | return $proto->password_get_info(@_); | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | =item hash($password, %options) | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | Proxy method for C<password_hash($password, $algo, %options)>. | ||||||||||||||||||||||||||||||||||||||||||
| 510 | The difference is that this method does have an $algo argument, | ||||||||||||||||||||||||||||||||||||||||||
| 511 | but instead allows the algorithm to be specified with the 'algo' option (in %options). | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | sub hash { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 9 | ▶ | my $proto = @_ && UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash: called CC=6 SCAR=21.6
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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 9 | my $password = shift; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 9 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 9 | ▶ | my $algo = $options{'algo'} || PASSWORD_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{'algo'} || 1
MC/DC0%0/1
$options{'algo'} || 1
$options{'algo'}
Truth table50%1/2
A
A= $options{'algo'}
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 9 | delete($options{'algo'}); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 9 | return $proto->password_hash($password, $algo, %options); | |||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | =item needs_rehash($crypted, $algo, %options) | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | Alias of C<password_needs_rehash($crypted, $algo, %options)>. | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | sub needs_rehash { | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 12 | return $proto->password_needs_rehash(@_); | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | =item verify($password, $crypted) | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | Alias of C<verify($password, $crypted)>. | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | sub verify { | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 25 | return $proto->password_verify(@_); | |||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | __END__ | ||||||||||||||||||||||||||||||||||||||||||