Browse Source

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 <noreply@anthropic.com>
feat/registration-page
npmrun 2 weeks ago
parent
commit
bf03b50ae3
  1. 3
      app/components/register/PasswordStrength.vue
  2. 6
      app/components/register/__tests__/PasswordStrength.test.ts

3
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

6
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')

Loading…
Cancel
Save