Grav版本是1.1.5
我删除了源代码中的每个验证逻辑和验证模式,但它不起作用,我在创建用户时仍然出错。
错误消息名称为USERNAME_NOT_VALID
,我在所有源代码中搜索并删除相关代码,但在出现错误时仍会显示在屏幕上。我不明白来自哪里的信息。
diff --git a/user/plugins/admin/pages/admin/register.md b/user/plugins/admin/pages/admin/register.md
index ff0b13b..fc0cf6e 100644
--- a/user/plugins/admin/pages/admin/register.md
+++ b/user/plugins/admin/pages/admin/register.md
@@ -9,7 +9,7 @@ form:
validate:
required: true
message: PLUGIN_LOGIN.USERNAME_NOT_VALID
- pattern: '^[a-z0-9_-]{3,16}$'
+ pattern: ''
- name: email
type: email
@@ -27,7 +27,7 @@ form:
validate:
required: true
message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE
- pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+ pattern: ''
- name: password2
type: password
@@ -36,7 +36,7 @@ form:
validate:
required: true
message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE
- pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+ pattern: ''
- name: fullname
type: text
diff --git a/user/plugins/login/pages/register.md b/user/plugins/login/pages/register.md
index c4088e2..0391367 100644
--- a/user/plugins/login/pages/register.md
+++ b/user/plugins/login/pages/register.md
@@ -12,7 +12,7 @@ form:
validate:
required: true
message: PLUGIN_LOGIN.USERNAME_NOT_VALID
- pattern: '^[a-z0-9_-]{3,16}$'
+ pattern: ''
-
name: email
@@ -31,7 +31,7 @@ form:
validate:
required: true
message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
- pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+ pattern: ''
-
name: password2
@@ -41,7 +41,7 @@ form:
validate:
required: true
message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
- pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+ pattern: ''
buttons:
-
diff --git a/user/plugins/login/pages/reset.md b/user/plugins/login/pages/reset.md
index e5f82e4..8300d2a 100644
--- a/user/plugins/login/pages/reset.md
+++ b/user/plugins/login/pages/reset.md
@@ -20,7 +20,7 @@ form:
validate:
required: true
message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
- pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+ pattern: ''
- name: token
type: hidden
diff --git a/user/plugins/login/cli/ChangePasswordCommand.php b/user/plugins/login/cli/ChangePasswordCommand.php
index d15abb7..5bde6cc 100644
--- a/user/plugins/login/cli/ChangePasswordCommand.php
+++ b/user/plugins/login/cli/ChangePasswordCommand.php
@@ -134,9 +134,6 @@ class ChangePasswordCommand extends ConsoleCommand
{
switch ($type) {
case 'user':
- if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
- throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
- }
if (!file_exists(self::getGrav()['locator']->findResource('account://' . $value . YAML_EXT))) {
throw new \RuntimeException('Username "' . $value . '" does not exist, please pick another username');
}
@@ -144,10 +141,6 @@ class ChangePasswordCommand extends ConsoleCommand
break;
case 'password1':
- if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
- throw new \RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
- }
-
break;
case 'password2':
diff --git a/user/plugins/login/cli/ChangeUserStateCommand.php b/user/plugins/login/cli/ChangeUserStateCommand.php
index 40f9dc6..90adee6 100644
--- a/user/plugins/login/cli/ChangeUserStateCommand.php
+++ b/user/plugins/login/cli/ChangeUserStateCommand.php
@@ -133,9 +133,6 @@ class ChangeUserStateCommand extends ConsoleCommand
{
switch ($type) {
case 'user':
- if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
- throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
- }
if (!file_exists(self::getGrav()['locator']->findResource('account://' . $value . YAML_EXT))) {
throw new \RuntimeException('Username "' . $value . '" does not exist, please pick another username');
}
diff --git a/user/plugins/login/cli/NewUserCommand.php b/user/plugins/login/cli/NewUserCommand.php
index 17dbf48..728adda 100644
--- a/user/plugins/login/cli/NewUserCommand.php
+++ b/user/plugins/login/cli/NewUserCommand.php
@@ -237,9 +237,6 @@ class NewUserCommand extends ConsoleCommand
{
switch ($type) {
case 'user':
- if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
- throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
- }
if (file_exists(Grav::instance()['locator']->findResource('account://' . $value . YAML_EXT))) {
throw new \RuntimeException('Username "' . $value . '" already exists, please pick another username');
}
@@ -247,10 +244,6 @@ class NewUserCommand extends ConsoleCommand
break;
case 'password1':
- if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
- throw new \RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
- }
-
break;
case 'password2':
答案 0 :(得分:1)
已经有一种方法可以直接包含在Grav中,而无需触及源代码。
如果你进入管理面板,在配置下,有一个名为“高级”的项目,你可以分别自定义“用户名正则表达式”和“密码正则表达式”
默认情况下,用户名正则表达式为^[a-z0-9_-]{3,16}$
,如@Scuzzy在评论中所述,可以更改为^(.*)^
以接受每个字符。
顺便提一下BTW的安全性和可读性,我建议你不要使用那个正则表达式,除非你想要在你的网站上使用像^ = - èö这样的unsernames。
我建议您不要直接触摸Grav源代码,因为每次更新Grav时都可以恢复每个更改。如果您真的想要在源代码中更改某些内容,请考虑将其创建为插件(即使是个人使用),这样您就可以更新。