-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
33 lines (28 loc) · 990 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use Kirby\Toolkit\I18n;
Kirby::plugin('visionbites/password-policy', [
'hooks' => [
'user.changePassword:before' => function ($user, $password) {
if (!checkPassword($password)) {
throw new Exception(I18n::translate('visionbites.password-policy.error-message'));
}
},
'user.create:before' => function (Kirby\Cms\User $user, array $input) {
if (!checkPassword($input['password'])) {
throw new Exception(I18n::translate('visionbites.password-policy.error-message'));
}
}
],
'options' => [
// Example criteria: at least 12 characters long, includes a number and a special character
'password_regex' => '/^(?=.*[0-9])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{12,}$/',
],
'translations' => array(
'en' => require_once __DIR__ . '/languages/en.php',
'de' => require_once __DIR__ . '/languages/de.php',
),
]);
function checkPassword($password) {
$regex = option('visionbites.password-policy.password_regex') ;
return preg_match($regex, $password);
}