| 1 | package Articulate::Authentication::Preconfigured; | ||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use Digest::SHA; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use Articulate::Storage; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use Time::HiRes; # overrides time() | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | =head1 NAME | ||||||||||||
| 12 | |||||||||||||
| 13 | Articulate::Authentication::Preconfigured - do not use this in production | ||||||||||||
| 14 | |||||||||||||
| 15 | =cut | ||||||||||||
| 16 | |||||||||||||
| 17 | =head1 WARNING | ||||||||||||
| 18 | |||||||||||||
| 19 | Warning: This is highly insecure, you will be storing your passwords in plain text in the configuration file. | ||||||||||||
| 20 | |||||||||||||
| 21 | It is suitable only for getting a project started, and should be promptly removed when a user account has been created which stores encrypted passwords somewhere. | ||||||||||||
| 22 | |||||||||||||
| 23 | =head1 CONFIGURATION | ||||||||||||
| 24 | |||||||||||||
| 25 | authentication: | ||||||||||||
| 26 | Articulate::Authentication: | ||||||||||||
| 27 | providers: | ||||||||||||
| 28 | - class: Articulate::Authentication::Preconfigured | ||||||||||||
| 29 | args: | ||||||||||||
| 30 | passwords: | ||||||||||||
| 31 | username: insecure_password | ||||||||||||
| 32 | |||||||||||||
| 33 | =head1 ATTRIBUTES | ||||||||||||
| 34 | |||||||||||||
| 35 | =head3 passwords | ||||||||||||
| 36 | |||||||||||||
| 37 | A simple hash of keys and values where the user is the key and the password is the value. | ||||||||||||
| 38 | |||||||||||||
| 39 | =cut | ||||||||||||
| 40 | |||||||||||||
| 41 | has passwords => ( | ||||||||||||
| 42 | is => 'rw', | ||||||||||||
| 43 | 0 | ▶ | default => sub { {} }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 44 | 1 | ); | |||||||||||
| 45 | |||||||||||||
| 46 | =head3 authenticate | ||||||||||||
| 47 | |||||||||||||
| 48 | $self->authenticate( $credentials ); | ||||||||||||
| 49 | |||||||||||||
| 50 | Accepts and returns the credentials if the C<password> matches the C<user_id>. Always returns the credentials passed in. | ||||||||||||
| 51 | |||||||||||||
| 52 | =cut | ||||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | sub authenticate { | ||||||||||
|
Subroutine
authenticate: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||
| 56 | 0 | my $credentials = shift; | |||||||||||
| 57 | 0 | ▶ | my $user_id = $credentials->fields->{user_id} // return; | ||||||||||
|
Condition0%0/2
$credentials->fields->{"user_id"} // (return)
MC/DC0%0/1
$credentials->fields->{"user_id"} // (return)
$credentials->fields->{"user_id"}
Truth table0%0/2
A
A= $credentials->fields->{"user_id"}
| |||||||||||||
| 58 | 0 | ▶ | my $password = $credentials->fields->{password} // return; | ||||||||||
|
Condition0%0/2
$credentials->fields->{"password"} // (return)
MC/DC0%0/1
$credentials->fields->{"password"} // (return)
$credentials->fields->{"password"}
Truth table0%0/2
A
A= $credentials->fields->{"password"}
| |||||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | if ( exists $self->passwords->{$user_id} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | return $credentials->accept('Passwords match') | ||||||||||||
| 62 | 0 | ▶ | if $password eq $self->passwords->{$user_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | # if we ever need to know if the user does not exist, now is the time to ask, | ||||||||||||
| 66 | # but we do not externally expose the difference between | ||||||||||||
| 67 | # "user not found" and "password doesn't match" | ||||||||||||
| 68 | 0 | return $credentials; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | 1; | |||||||||||