-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrengthChecker.html
More file actions
370 lines (327 loc) · 11.5 KB
/
Copy pathPasswordStrengthChecker.html
File metadata and controls
370 lines (327 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>密码强度检测器 - JustHTML 只需网页</title>
<script>
/**
* 动态加载(强制去除缓存) CSS 的函数
* @param {string} src - 要加载的 CSS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadStyle(src) {
return new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
link.async = true;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}
/**
* 动态加载(强制去除缓存) JS 的函数
* @param {string} src - 要加载的 JS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
</script>
<script>
loadStyle('../assets/style.css')
let scriptArray = [
"../assets/AddHeader_Tools.js",
"../assets/AddFooter.js",
"../assets/AddIco.js",
"../assets/AutoRun.js",
]
scriptArray.forEach(script => {
loadScript(script);
});
</script>
<script src="../package/Vue/code/vue.global.prod.js"></script>
<script type="module" src="../package/Sober/code/main.js"></script>
<style>
.password-checker {
max-width: 600px;
margin: 0 auto;
}
.input-group {
margin: 15px 0;
}
.input-group label {
display: block;
margin-bottom: 5px;
color: var(--accent-color);
}
.input-group input {
width: 100%;
padding: 8px;
}
.strength-meter {
height: 10px;
background-color: var(--bg-secondary);
border-radius: 5px;
margin: 15px 0;
overflow: hidden;
}
.strength-fill {
height: 100%;
width: 0%;
transition: width 0.3s ease;
}
.strength-very-weak { background-color: #e74c3c; }
.strength-weak { background-color: #f39c12; }
.strength-medium { background-color: #3498db; }
.strength-strong { background-color: #f1c40f; }
.strength-very-strong { background-color: #2ecc71; }
.strength-label {
text-align: center;
font-weight: bold;
}
.strength-very-weak-text { color: #e74c3c; }
.strength-weak-text { color: #f39c12; }
.strength-medium-text { color: #3498db; }
.strength-strong-text { color: #f1c40f; }
.strength-very-strong-text { color: #2ecc71; }
.criteria-list {
margin: 15px 0;
padding: 15px;
background-color: var(--bg-tertiary);
border-radius: var(--border-radius);
}
.criteria-item {
display: flex;
align-items: center;
margin: 8px 0;
}
.criteria-icon {
width: 20px;
height: 20px;
margin-right: 10px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
}
.icon-passed { background-color: #2ecc71; color: white; }
.icon-failed { background-color: #e74c3c; color: white; }
.info-box {
background-color: var(--bg-tertiary);
padding: 10px;
border-radius: var(--border-radius);
margin: 10px 0;
}
.tips {
margin-top: 20px;
padding: 15px;
background-color: var(--bg-tertiary);
border-radius: var(--border-radius);
}
.tip-item {
margin: 10px 0;
padding: 10px;
background-color: var(--bg-secondary);
border-radius: 4px;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<a href="../index.html" class="back-link">← 返回首页</a>
<div class="tool-section password-checker">
<h2>密码强度检测器</h2>
<p>检测密码的安全强度</p>
<div class="info-box">
<p><strong>功能说明:</strong></p>
<p>• 实时检测密码强度</p>
<p>• 显示密码安全性详细分析</p>
<p>• 提供改善密码强度的建议</p>
</div>
<div>
<div class="input-group">
<label for="password">输入密码</label>
<input
type="password"
id="password"
v-model="password"
placeholder="输入要检测的密码"
@input="checkStrength"
>
</div>
<div class="strength-meter">
<div
class="strength-fill"
:class="strengthClass"
:style="{ width: strengthPercent + '%' }"
></div>
</div>
<div class="strength-label" :class="strengthLabelClass">
密码强度: {{ strengthText }}
</div>
<div class="criteria-list">
<h3>密码安全要素</h3>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.minLength, 'icon-failed': !criteria.minLength}">
{{ criteria.minLength ? '✓' : '✗' }}
</div>
<span>至少8个字符</span>
</div>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.uppercase, 'icon-failed': !criteria.uppercase}">
{{ criteria.uppercase ? '✓' : '✗' }}
</div>
<span>包含大写字母</span>
</div>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.lowercase, 'icon-failed': !criteria.lowercase}">
{{ criteria.lowercase ? '✓' : '✗' }}
</div>
<span>包含小写字母</span>
</div>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.numbers, 'icon-failed': !criteria.numbers}">
{{ criteria.numbers ? '✓' : '✗' }}
</div>
<span>包含数字</span>
</div>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.symbols, 'icon-failed': !criteria.symbols}">
{{ criteria.symbols ? '✓' : '✗' }}
</div>
<span>包含特殊符号</span>
</div>
<div class="criteria-item">
<div class="criteria-icon" :class="{'icon-passed': criteria.noCommon, 'icon-failed': !criteria.noCommon}">
{{ criteria.noCommon ? '✓' : '✗' }}
</div>
<span>不是常见密码</span>
</div>
</div>
<div class="tips">
<h3>密码安全建议</h3>
<div class="tip-item">
<p>创建安全密码的方法:</p>
<ul>
<li>使用12个或更多字符</li>
<li>混合使用大写、小写字母、数字和特殊字符</li>
<li>避免使用个人信息(生日、姓名等)</li>
<li>避免使用常见的单词或短语</li>
<li>每个账户使用唯一密码</li>
<li>考虑使用密码管理器</li>
<li>启用双因素认证</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const { createApp, ref, reactive, computed } = Vue;
createApp({
setup() {
const password = ref('');
const criteria = reactive({
minLength: false,
uppercase: false,
lowercase: false,
numbers: false,
symbols: false,
noCommon: true
});
// 常见的弱密码列表
const commonPasswords = [
'password', '123456', 'qwerty', 'abc123', 'password123',
'admin', 'letmein', 'welcome', 'monkey', 'dragon',
'master', 'hello', 'freedom', 'whatever', 'trustno1',
'654321', '123123', 'password1', '1234567890', '0987654321'
];
// 计算密码强度
const strengthPercent = computed(() => {
if (!password.value) return 0;
let score = 0;
// 长度评分
if (password.value.length >= 8) score += 20;
if (password.value.length >= 12) score += 10;
if (password.value.length >= 16) score += 10;
// 字符类型评分
if (criteria.uppercase) score += 10;
if (criteria.lowercase) score += 10;
if (criteria.numbers) score += 10;
if (criteria.symbols) score += 10;
// 非常见密码评分
if (criteria.noCommon) score += 20;
return Math.min(score, 100);
});
const strengthText = computed(() => {
if (strengthPercent.value < 20) return '非常弱';
if (strengthPercent.value < 40) return '弱';
if (strengthPercent.value < 60) return '中等';
if (strengthPercent.value < 80) return '强';
return '非常强';
});
const strengthClass = computed(() => {
if (strengthPercent.value < 20) return 'strength-very-weak';
if (strengthPercent.value < 40) return 'strength-weak';
if (strengthPercent.value < 60) return 'strength-medium';
if (strengthPercent.value < 80) return 'strength-strong';
return 'strength-very-strong';
});
const strengthLabelClass = computed(() => {
if (strengthPercent.value < 20) return 'strength-very-weak-text';
if (strengthPercent.value < 40) return 'strength-weak-text';
if (strengthPercent.value < 60) return 'strength-medium-text';
if (strengthPercent.value < 80) return 'strength-strong-text';
return 'strength-very-strong-text';
});
// 检测密码强度
const checkStrength = () => {
if (!password.value) {
// 重置所有条件
criteria.minLength = false;
criteria.uppercase = false;
criteria.lowercase = false;
criteria.numbers = false;
criteria.symbols = false;
criteria.noCommon = true;
return;
}
// 检查长度
criteria.minLength = password.value.length >= 8;
// 检查字符类型
criteria.uppercase = /[A-Z]/.test(password.value);
criteria.lowercase = /[a-z]/.test(password.value);
criteria.numbers = /[0-9]/.test(password.value);
criteria.symbols = /[^A-Za-z0-9]/.test(password.value);
// 检查是否为常见密码
const lowerPassword = password.value.toLowerCase();
criteria.noCommon = !commonPasswords.some(commonPass =>
lowerPassword.includes(commonPass) || commonPass.includes(lowerPassword)
);
};
return {
password,
criteria,
strengthPercent,
strengthText,
strengthClass,
strengthLabelClass,
checkStrength
};
}
}).mount('#app');
</script>
</body>
</html>