From bf03b50ae3fa5c3cba50576821302e531d363863 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Fri, 15 May 2026 16:17:06 +0800 Subject: [PATCH] fix: accept any letter case for password strength score 2 Score 2 (letters+digits >=8) previously only matched lowercase letters. Now uses hasLetter = hasLower || hasUpper to match the spec's intent. Added test case for uppercase-only + digits password. Co-Authored-By: Claude Opus 4.7 --- app/components/register/PasswordStrength.vue | 3 ++- app/components/register/__tests__/PasswordStrength.test.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/components/register/PasswordStrength.vue b/app/components/register/PasswordStrength.vue index debcbf8..9be10cb 100644 --- a/app/components/register/PasswordStrength.vue +++ b/app/components/register/PasswordStrength.vue @@ -11,7 +11,8 @@ const score = computed(() => { const hasDigit = /\d/.test(p) const hasSpecial = /[^a-zA-Z\d]/.test(p) - if (p.length >= 8 && hasLower && hasDigit) s = 2 + const hasLetter = hasLower || hasUpper + if (p.length >= 8 && hasLetter && hasDigit) s = 2 if (p.length >= 10 && hasLower && hasUpper && hasDigit) s = 3 if (p.length >= 12 && hasLower && hasUpper && hasDigit && hasSpecial) s = 4 // Fallback: any input < 8 or single-type = weak diff --git a/app/components/register/__tests__/PasswordStrength.test.ts b/app/components/register/__tests__/PasswordStrength.test.ts index 82b70ef..37f9433 100644 --- a/app/components/register/__tests__/PasswordStrength.test.ts +++ b/app/components/register/__tests__/PasswordStrength.test.ts @@ -25,6 +25,12 @@ describe('PasswordStrength', () => { expect(wrapper.text()).toContain('中') }) + it('score 2 for uppercase letters+digits >= 8 chars', () => { + const wrapper = mount(PasswordStrength, { props: { password: 'ABC12345' } }) + expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('2') + expect(wrapper.text()).toContain('中') + }) + it('score 3 for upper+lower+digits >= 10 chars', () => { const wrapper = mount(PasswordStrength, { props: { password: 'Abcdef1234' } }) expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('3')