Use new password and username regex from grav system config

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
Andy Miller
2017-04-13 14:56:32 -06:00
parent 8cffa71cc6
commit 46afadf5d4
4 changed files with 20 additions and 10 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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"

View File

@@ -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