2017-02-13 59 views
1

Grav版本是1.1.5如何在Grav中禁用用户名验证?

我删除了源代码中的每个验证逻辑和验证模式,但它不起作用,我创建用户时仍然出错。

错误信息名称为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': 
+2

我不知道什么是Grav,但是如果你打算把''^ [a-z0-9 _-] {3,16} $''改成''''你可能想把' '*''所以至少有一个有效的模式。 – Scuzzy

回答

1

已经有一种方法可以直接包含在Grav中,而无需触及源代码。

如果您在管理面板去,在配置下,有一个叫做项目“高级”在这里你可以分别自定义“用户名正则表达式”和“密码正则表达式”

默认情况下,用户名正则表达式是^[a-z0-9_-]{3,16}$和可,如@Scuzzy在评论中所述,更改为^(.*)^接受每个角色。

顺便说一句,安全性和可读性明智,我建议你不要使用该正则表达式,除非你想在你的网站上使用像^ = - èö这样的非名称。

我建议您避免直接触摸Grav源代码,因为每次更新Grav时都可以恢复每次更改。如果你真的想在源代码中改变某些东西,可以考虑将它创建为一个插件(即使是为了个人使用),以便保持更新的能力。

+0

'^(。*)^'和'。*'有什么不同?大胆的工作。 –