diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index 0f08b347f..25e780cdd 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -4,7 +4,7 @@ from django.db.models import Count from common.mixins.serializers import BulkSerializerMixin from common.utils import ssh_pubkey_gen -from common.validators import alphanumeric_re, alphanumeric_cn_re +from common.validators import alphanumeric_re, alphanumeric_cn_re, alphanumeric_win_re from orgs.mixins.serializers import BulkOrgResourceModelSerializer from ..models import SystemUser, Asset from .utils import validate_password_contains_left_double_curly_bracket @@ -107,9 +107,12 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): def validate_username(self, username): protocol = self.get_initial_value("protocol") if username: - regx = alphanumeric_re - if protocol == SystemUser.Protocol.telnet or protocol == SystemUser.Protocol.rdp: + if protocol == SystemUser.Protocol.telnet: regx = alphanumeric_cn_re + elif protocol == SystemUser.Protocol.rdp: + regx = alphanumeric_win_re + else: + regx = alphanumeric_re if not regx.match(username): raise serializers.ValidationError(_('Special char not allowed')) return username diff --git a/apps/common/validators.py b/apps/common/validators.py index 0c81b1e4e..352482a1b 100644 --- a/apps/common/validators.py +++ b/apps/common/validators.py @@ -15,7 +15,9 @@ alphanumeric = RegexValidator(r'^[0-9a-zA-Z_@\-\.]*$', _('Special char not allow alphanumeric_re = re.compile(r'^[0-9a-zA-Z_@\-\.]*$') -alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\$\-\.\u4E00-\u9FA5]*$') +alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\-\.\u4E00-\u9FA5]*$') + +alphanumeric_win_re = re.compile(r'^[0-9a-zA-Z_@#%&~\^\$\-\.\u4E00-\u9FA5]*$') class ProjectUniqueValidator(UniqueTogetherValidator):