From ee9357cad6e4b951267aac70b0e753b6c81c47b9 Mon Sep 17 00:00:00 2001 From: IGeekFan Date: Sun, 19 May 2024 21:56:44 +0800 Subject: [PATCH] update password regex valid --- .../Cms/Account/RegisterDto.cs | 3 +-- .../Cms/Account/ResetEmailPasswordDto.cs | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs b/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs index 15368d2a..26feed3d 100644 --- a/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs +++ b/src/LinCms.Application.Contracts/Cms/Account/RegisterDto.cs @@ -12,7 +12,6 @@ public class RegisterEmailCodeInput : IValidatableObject [Required(ErrorMessage = "邮件不能为空")] public string Email { get; set; } - public IEnumerable Validate(ValidationContext validationContext) { if (!Email.IsNullOrEmpty()) @@ -50,7 +49,7 @@ public class RegisterDto : RegisterEmailCodeInput /// 密码 /// [Required(ErrorMessage = "新密码不可为空")] - [RegularExpression("^[A-Za-z0-9_*&$#@]{6,22}$", ErrorMessage = "密码长度必须在6~22位之间,包含字符、数字和 _")] + [RegularExpression(AccountContract.PasswordRegex, ErrorMessage = AccountContract.PasswordErrorMessage)] public string Password { get; set; } /// diff --git a/src/LinCms.Application.Contracts/Cms/Account/ResetEmailPasswordDto.cs b/src/LinCms.Application.Contracts/Cms/Account/ResetEmailPasswordDto.cs index e1bfac10..e0fbc89a 100644 --- a/src/LinCms.Application.Contracts/Cms/Account/ResetEmailPasswordDto.cs +++ b/src/LinCms.Application.Contracts/Cms/Account/ResetEmailPasswordDto.cs @@ -12,6 +12,12 @@ public class ResetEmailPasswordDto [Required(ErrorMessage = "请输入验证码")] public string ResetCode { get; set; } [Required(ErrorMessage = "请输入你的新密码")] - [RegularExpression("^[A-Za-z0-9_*&$#@]{6,22}$", ErrorMessage = "密码长度必须在6~22位之间,包含字符、数字和 _")] + [RegularExpression(AccountContract.PasswordRegex, ErrorMessage = AccountContract.PasswordErrorMessage)] public string Password { get; set; } +} + +public class AccountContract +{ + public const string PasswordRegex = "^(?![a-zA-Z]+$)(?!\\d+$)(?![^\\da-zA-Z\\s]+$).{6,20}$"; + public const string PasswordErrorMessage = "密码由字母、数字、特殊字符,任意2种组成,长度在6-20个字符之间"; } \ No newline at end of file