fix(web): unify password validation logic in RegisterPage (#943)

Remove duplicate password validation logic to ensure consistency.
Changes:
- Remove custom isStrongPassword function (RegisterPage.tsx:569-576)
- Use PasswordChecklist validation result (passwordValid state) instead
- Add comprehensive test suite with 28 test cases
- Configure Vitest with jsdom environment and setup file
Test Coverage:
- Password validation rules (length, uppercase, lowercase, number, special chars)
- Special character consistency (/[@#$%!&*?]/)
- Edge cases and boundary conditions
- Refactoring consistency verification
All 78 tests passing (25 + 25 + 28).
Co-authored-by: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
Ember
2025-11-12 21:54:54 +08:00
committed by GitHub
parent 9e5688609e
commit bfb409e8a1
4 changed files with 423 additions and 13 deletions

View File

@@ -47,9 +47,8 @@ export function RegisterPage() {
e.preventDefault()
setError('')
// 客户端强校验:长度>=8包含大小写、数字、特殊字符且两次一致
const strong = isStrongPassword(password)
if (!strong || password !== confirmPassword) {
// 使用 PasswordChecklist 的校验结果
if (!passwordValid) {
setError(t('passwordNotMeetRequirements', language))
return
}
@@ -565,13 +564,3 @@ export function RegisterPage() {
</div>
)
}
// 本地密码强度校验(与 UI 规则一致)
function isStrongPassword(pwd: string): boolean {
if (!pwd || pwd.length < 8) return false
const hasUpper = /[A-Z]/.test(pwd)
const hasLower = /[a-z]/.test(pwd)
const hasNumber = /\d/.test(pwd)
const hasSpecial = /[@#$%!&*?]/.test(pwd)
return hasUpper && hasLower && hasNumber && hasSpecial
}