system-phone 3.1.93 → 3.1.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,172 +1,185 @@
1
1
  const REG_STRONG_PWD =
2
- /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?])(?!.*(123|321|abc|cba))[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{8,16}$/;
2
+ /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*(),.?":{}|<>~`+=_\\-])[A-Za-z\d!@#$%^&*(),.?":{}|<>~`+=_\\-]{12,16}$/
3
3
 
4
- // 常见密码列表(可以根据需要扩展)
5
4
  const COMMON_PASSWORDS = [
6
- "password",
7
- "password123",
8
- "123456",
9
- "12345678",
10
- "qwerty",
11
- "abc123",
12
- "Password1",
13
- "password1",
14
- "123456789",
15
- "welcome",
16
- "admin",
17
- "letmein",
18
- "monkey",
19
- "dragon",
20
- "master",
21
- "superman",
22
- "qwerty123",
23
- "admin123",
24
- "root",
25
- "pass",
26
- "test",
27
- "guest",
28
- "user",
29
- "000000",
30
- "111111",
31
- "666666",
32
- "888888",
33
- "999999",
34
- "iloveyou",
35
- "welcome123",
36
- "password!",
37
- "Passw0rd!",
38
- "Passw0rd",
39
- "Password!",
40
- "passw0rd",
41
- "P@ssw0rd",
42
- "P@ssword",
43
- "Password@123",
44
- ];
45
-
46
- // 检查连续数字(3个或以上)
47
- const hasConsecutiveNumbers = (password) => {
5
+ 'password',
6
+ 'password123',
7
+ '123456',
8
+ '12345678',
9
+ 'qwerty',
10
+ 'abc123',
11
+ 'Password1',
12
+ 'password1',
13
+ '123456789',
14
+ 'welcome',
15
+ 'admin',
16
+ 'letmein',
17
+ 'monkey',
18
+ 'dragon',
19
+ 'master',
20
+ 'superman',
21
+ 'qwerty123',
22
+ 'admin123',
23
+ 'root',
24
+ 'pass',
25
+ 'test',
26
+ 'guest',
27
+ 'user',
28
+ '000000',
29
+ '111111',
30
+ '666666',
31
+ '888888',
32
+ '999999',
33
+ 'iloveyou',
34
+ 'welcome123',
35
+ 'password!',
36
+ 'Passw0rd!',
37
+ 'Passw0rd',
38
+ 'Password!',
39
+ 'passw0rd',
40
+ 'P@ssw0rd',
41
+ 'P@ssword',
42
+ 'Password@123'
43
+ ]
44
+
45
+ export const PASSWORD_RULE_HINT = '密码长度须为 12-16 位,包含大小写字母、数字与特殊符号。'
46
+
47
+ export const PASSWORD_DEFAULT_ERROR = '新密码必须包含大小写字母、数字和特殊字符,且长度为12-16位'
48
+
49
+ function hasConsecutiveNumbers (password) {
48
50
  for (let i = 0; i <= password.length - 3; i++) {
49
- const substr = password.substring(i, i + 3);
51
+ const substr = password.substring(i, i + 3)
50
52
  if (/^\d{3,}$/.test(substr)) {
51
- // 检查是否为连续数字
52
- const digits = substr.split("").map(Number);
53
- let isConsecutive = true;
53
+ const digits = substr.split('').map(Number)
54
+ let isConsecutive = true
54
55
  for (let j = 1; j < digits.length; j++) {
55
56
  if (digits[j] !== digits[j - 1] + 1) {
56
- isConsecutive = false;
57
- break;
57
+ isConsecutive = false
58
+ break
58
59
  }
59
60
  }
60
- if (isConsecutive) return true;
61
+ if (isConsecutive) return true
61
62
  }
62
63
  }
63
- return false;
64
- };
64
+ return false
65
+ }
65
66
 
66
- // 检查连续字母(3个或以上)
67
- const hasConsecutiveLetters = (password) => {
68
- const lowerPassword = password.toLowerCase();
67
+ function hasConsecutiveLetters (password) {
68
+ const lowerPassword = password.toLowerCase()
69
69
  for (let i = 0; i <= lowerPassword.length - 3; i++) {
70
- const substr = lowerPassword.substring(i, i + 3);
70
+ const substr = lowerPassword.substring(i, i + 3)
71
71
  if (/^[a-z]{3,}$/.test(substr)) {
72
- // 检查是否为连续字母
73
- let isConsecutive = true;
72
+ let isConsecutive = true
74
73
  for (let j = 1; j < substr.length; j++) {
75
74
  if (substr.charCodeAt(j) !== substr.charCodeAt(j - 1) + 1) {
76
- isConsecutive = false;
77
- break;
75
+ isConsecutive = false
76
+ break
78
77
  }
79
78
  }
80
- if (isConsecutive) return true;
79
+ if (isConsecutive) return true
81
80
  }
82
81
  }
83
- return false;
84
- };
85
-
86
- // 检查重复字符(3个或以上相同字符)
87
- const hasRepeatedChars = (password) => {
88
- return /(.)\1{2,}/.test(password);
89
- };
90
-
91
- // 检查键盘连续按键(如 qwerty, asdf 等)
92
- const hasKeyboardPattern = (password) => {
93
- const keyboardRows = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
94
- const lowerPassword = password.toLowerCase();
82
+ return false
83
+ }
84
+
85
+ function hasRepeatedChars (password) {
86
+ return /(.)\1{2,}/.test(password)
87
+ }
88
+
89
+ function hasKeyboardPattern (password) {
90
+ const keyboardRows = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm', '1234567890']
91
+ const lowerPassword = password.toLowerCase()
92
+
95
93
  for (const row of keyboardRows) {
96
94
  for (let i = 0; i <= row.length - 3; i++) {
97
- const pattern = row.substring(i, i + 3);
95
+ const pattern = row.substring(i, i + 3)
98
96
  if (lowerPassword.includes(pattern)) {
99
- return true;
97
+ return true
100
98
  }
101
99
  }
102
100
  }
103
- return false;
104
- };
105
-
106
- /**
107
- * 密码校验结果对象
108
- * @typedef {Object} PasswordValidationResult
109
- * @property {boolean} isValid
110
- * @property {string[]} errors
111
- */
112
-
113
- /**
114
- * 增强的密码校验函数
115
- * @param {string} password
116
- * @returns {PasswordValidationResult}
117
- */
101
+ return false
102
+ }
103
+
118
104
  export const validateStrongPasswordPhone = (password) => {
119
105
  const result = {
120
106
  isValid: true,
121
- errors: [],
122
- };
107
+ errors: []
108
+ }
109
+
110
+ if (!password) {
111
+ result.isValid = false
112
+ result.errors.push('不能为空')
113
+ return result
114
+ }
123
115
 
124
- // 1. 基本格式校验
125
116
  if (!REG_STRONG_PWD.test(password)) {
126
- result.isValid = false;
127
- result.errors.push(
128
- "密码长度必须为8-16位,且需同时包含大写字母、小写字母、数字和特殊字符"
129
- );
130
- return result;
117
+ result.isValid = false
118
+ result.errors.push('密码长度须为12-16位,且包含大写字母、小写字母、数字和特殊字符')
119
+ return result
131
120
  }
132
121
 
133
- // 2. 检查是否为常见密码
134
- if (
135
- COMMON_PASSWORDS.includes(password) ||
136
- COMMON_PASSWORDS.includes(password.toLowerCase())
137
- ) {
138
- result.isValid = false;
139
- result.errors.push("不能使用常见密码");
140
- return result;
122
+ if (COMMON_PASSWORDS.includes(password) || COMMON_PASSWORDS.includes(password.toLowerCase())) {
123
+ result.isValid = false
124
+ result.errors.push('不能使用常见密码')
125
+ return result
141
126
  }
142
127
 
143
- // 3. 检查连续数字
144
128
  if (hasConsecutiveNumbers(password)) {
145
- result.isValid = false;
146
- result.errors.push("不能包含连续数字");
147
- return result;
129
+ result.isValid = false
130
+ result.errors.push('不能包含连续数字')
131
+ return result
148
132
  }
149
133
 
150
- // 4. 检查连续字母
151
134
  if (hasConsecutiveLetters(password)) {
152
- result.isValid = false;
153
- result.errors.push("不能包含连续字母");
154
- return result;
135
+ result.isValid = false
136
+ result.errors.push('不能包含连续字母')
137
+ return result
155
138
  }
156
139
 
157
- // 5. 检查重复字符
158
140
  if (hasRepeatedChars(password)) {
159
- result.isValid = false;
160
- result.errors.push("不能包含3个或以上相同字符");
161
- return result;
141
+ result.isValid = false
142
+ result.errors.push('不能包含3个或以上相同字符')
143
+ return result
162
144
  }
163
145
 
164
- // 6. 检查键盘模式
165
146
  if (hasKeyboardPattern(password)) {
166
- result.isValid = false;
167
- result.errors.push("不能包含键盘连续按键模式");
168
- return result;
147
+ result.isValid = false
148
+ result.errors.push('不能包含键盘连续按键模式')
149
+ return result
169
150
  }
170
151
 
171
- return result;
172
- };
152
+ return result
153
+ }
154
+
155
+ export function isStrongPassword (password) {
156
+ return validateStrongPasswordPhone(password).isValid
157
+ }
158
+
159
+ export function getPasswordStrength (password) {
160
+ if (!password) {
161
+ return {
162
+ label: '未输入',
163
+ type: 'default',
164
+ desc: '请输入密码以查看强度',
165
+ visible: false
166
+ }
167
+ }
168
+
169
+ const { isValid, errors } = validateStrongPasswordPhone(password)
170
+ if (isValid) {
171
+ return {
172
+ label: '强',
173
+ type: 'success',
174
+ desc: '密码满足复杂度要求',
175
+ visible: true
176
+ }
177
+ }
178
+
179
+ return {
180
+ label: '弱',
181
+ type: 'error',
182
+ desc: errors[0] || '密码不满足安全要求',
183
+ visible: true
184
+ }
185
+ }