mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 14:56:57 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user