Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PasswordValidatorLoader | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
240 | |
0.00% |
0 / 1 |
| load | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
240 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2022 Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | declare(strict_types=1); |
| 23 | |
| 24 | namespace oat\tao\model\password; |
| 25 | |
| 26 | class PasswordValidatorLoader implements PasswordValidatorLoaderInterface |
| 27 | { |
| 28 | public function load(array $config): array |
| 29 | { |
| 30 | $validators = []; |
| 31 | |
| 32 | if (array_key_exists('length', $config) && (int) $config['length']) { |
| 33 | $validators[] = new \tao_helpers_form_validators_Length([ 'min' => (int) $config['length'] ]); |
| 34 | } |
| 35 | |
| 36 | if ( |
| 37 | (array_key_exists('upper', $config) && $config['upper']) |
| 38 | || (array_key_exists('lower', $config) && $config['lower']) |
| 39 | ) { |
| 40 | $validators[] = new \tao_helpers_form_validators_Regex( |
| 41 | [ |
| 42 | 'message' => __('Must include at least one letter'), |
| 43 | 'format' => '/\pL/' |
| 44 | ], |
| 45 | 'letters' |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | if (array_key_exists('upper', $config) && $config['upper']) { |
| 50 | $validators[] = new \tao_helpers_form_validators_Regex( |
| 51 | [ |
| 52 | 'message' => __('Must include upper case letters'), |
| 53 | 'format' => '/(\p{Lu}+)/', |
| 54 | ], |
| 55 | 'caseUpper' |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | if (array_key_exists('lower', $config) && $config['lower']) { |
| 60 | $validators[] = new \tao_helpers_form_validators_Regex( |
| 61 | [ |
| 62 | 'message' => __('Must include lower case letters'), |
| 63 | 'format' => '/(\p{Ll}+)/' |
| 64 | ], |
| 65 | 'caseLower' |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | if (array_key_exists('number', $config) && $config['number']) { |
| 70 | $validators[] = new \tao_helpers_form_validators_Regex( |
| 71 | [ |
| 72 | 'message' => __('Must include at least one number'), |
| 73 | 'format' => '/\pN/' |
| 74 | ], |
| 75 | 'number' |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | if (array_key_exists('spec', $config) && $config['spec']) { |
| 80 | $validators[] = new \tao_helpers_form_validators_Regex( |
| 81 | [ |
| 82 | 'message' => __('Must include at least one special letter'), |
| 83 | 'format' => '/[^p{Ll}\p{Lu}\pL\pN]/' |
| 84 | ], |
| 85 | 'spec' |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | return $validators; |
| 90 | } |
| 91 | } |