srvpath/User.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 47 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use Object::Pad ':experimental(:all)';
2  
3 package WWW::srvpath::User;
4 role WWW::srvpath::User : does(WWW::srvpath::User::Auth);
5  
6 use v5.44;
7 use utf8;
8  
9 use Net::SSLeay;
10 use IO::Handle::Common;
11  
12 field $userdb : reader = [];
13  
14 # TODO: Maybe use autoload to call in form of (class common technically) method
15  
16 method add_user ( $name, @pass ) {
17 my %user = ( user => $name );
18  
19 if ( scalar @pass == 1 ) {
20 $user{crypt} =
21 __CLASS__->is_argon2( $pass[0] )
22 ? $pass[0]
23 : hashpass( $pass[0] );
24 }
25 else {
26 my %pass = @pass;
27  
28 # TODO: eventually support reads from a different key
29 my $crypt_key = $user{crypt_key} = $pass{crypt_key} //= 'crypt';
30  
31 if ( $pass{password} ) {
32 $user{crypt} =
33 hashpass( $pass{password} );
34 }
35 elsif ( $pass{$crypt_key} ) {
36 fatal "Not a valid argon2 hash"
37 unless __CLASS__->is_argon2( $pass{$crypt_key} );
38  
39 $user{crypt} = $pass{$crypt_key};
40 }
41 else {
42 fatal "No cleartext password or argon2 hash given.";
43 }
44 }
45  
46 push @$userdb, \%user;
47 }