From 46afadf5d4aba7b85d2ed8c7b432920523c0fd5d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 13 Apr 2017 14:56:32 -0600 Subject: [PATCH] Use new password and username regex from grav system config # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 5 +++-- admin.php | 7 +++++-- languages/en.yaml | 6 ++++++ pages/admin/register.md | 12 ++++++------ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d997936..c91beaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -# v1.3.X -## XX/XX/2017 +# v1.4.0 +## 04/xx/2017 1. [](#improved) + * Use new system configuration entries for username and password format * More robust styling of admin themes page [#1067](https://github.com/getgrav/grav-plugin-admin/pull/1067) * Fix fullscreen editor height [#1065](https://github.com/getgrav/grav-plugin-admin/pull/1065) * Fix small UI issue in the editor with `codemirror.lineNumbers` && `codemirror.styleActiveLine` enabled diff --git a/admin.php b/admin.php index 50e6231e..d39dd406 100644 --- a/admin.php +++ b/admin.php @@ -155,16 +155,19 @@ class AdminPlugin extends Plugin */ protected function validate($type, $value, $extra = '') { + $username_regex = '/' . $this->config->get('system.username_regex') . '/'; + $pwd_regex = '/' . $this->config->get('system.pwd_regex') . '/'; + switch ($type) { case 'username_format': - if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) { + if (!preg_match($username_regex, $value)) { return false; } return true; case 'password1': - if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) { + if (!preg_match($pwd_regex, $value)) { return false; } diff --git a/languages/en.yaml b/languages/en.yaml index 61213831..8860be2f 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -664,3 +664,9 @@ PLUGIN_ADMIN: ADMIN_SPECIFIC_OVERRIDES: "Admin Specific Overrides" ADMIN_CHILDREN_DISPLAY_ORDER: "Children Display Order" ADMIN_CHILDREN_DISPLAY_ORDER_HELP: "The order that children of this page should be displayed in the 'Pages' view of Admin plugin" + PWD_PLACEHOLDER: "complex string at least 8 chars long" + PWD_REGEX: "Password Regex" + PWD_REGEX_HELP: "By default: Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" + USERNAME_PLACEHOLDER: "lowercase chars only, e.g. 'admin'" + USERNAME_REGEX: "Username Regex" + USERNAME_REGEX_HELP: "By default: Only lowercase chars, digits, dashes, and underscores. 3 - 16 chars" diff --git a/pages/admin/register.md b/pages/admin/register.md index ff0b13bb..aec38587 100644 --- a/pages/admin/register.md +++ b/pages/admin/register.md @@ -5,11 +5,11 @@ form: type: text label: PLUGIN_ADMIN.USERNAME autofocus: true - placeholder: "lowercase chars only, e.g. 'admin'" + placeholder: PLUGIN_ADMIN.USERNAME_PLACEHOLDER validate: required: true message: PLUGIN_LOGIN.USERNAME_NOT_VALID - pattern: '^[a-z0-9_-]{3,16}$' + config-pattern@: system.username_regex - name: email type: email @@ -23,20 +23,20 @@ form: - name: password1 type: password label: PLUGIN_ADMIN.PASSWORD - placeholder: "complex string at least 8 chars long" + placeholder: PLUGIN_ADMIN.PWD_PLACEHOLDER validate: required: true message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE - pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' + config-pattern@: system.pwd_regex - name: password2 type: password label: PLUGIN_ADMIN.PASSWORD_CONFIRM - placeholder: "complex string at least 8 chars long" + placeholder: PLUGIN_ADMIN.PWD_PLACEHOLDER validate: required: true message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE - pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' + config-pattern@: system.pwd_regex - name: fullname type: text