Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apps/extension/__tests__/vault-ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ describe('assessPassword', () => {
expect(assessPassword('')).toMatchObject({ score: 0, label: '' });
});

it('calls out a password that is simply too short', () => {
it('rates a very short password weak without demanding a minimum length', () => {
const result = assessPassword('Ab1!xy');
expect(result.label).toBe('Too short');
expect(result.hint).toMatch(/at least 12/);
expect(result.label).toBe('Weak');
expect(result.hint).not.toMatch(/at least/);
});

it('accepts an eleven-character password as a normal rating', () => {
const result = assessPassword('5stringerSS');
expect(result.label).toBe('Fair');
expect(result.score).toBeGreaterThanOrEqual(3);
});

it('rates a long mixed password highly', () => {
Expand Down
21 changes: 11 additions & 10 deletions apps/extension/src/popup/components/vault/VaultUnlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import React, { useState } from 'react';
* background/vault-session.js.
*/

const MIN_PASSWORD_LENGTH = 12;

/** Rough strength read, shown while choosing a master password. */
export function assessPassword(password) {
const value = String(password || '');
if (value.length === 0) return { score: 0, label: '', hint: '' };

// Length still dominates the rating, but it no longer gates anything: a short
// master password reads as weak and is accepted all the same.
if (value.length < 8) {
return { score: 1, label: 'Weak', hint: 'Short passwords are easy to guess' };
}

let score = 0;
if (value.length >= MIN_PASSWORD_LENGTH) score += 1;
if (value.length >= 8) score += 1;
if (value.length >= 16) score += 1;
if (/[a-z]/.test(value) && /[A-Z]/.test(value)) score += 1;
if (/\d/.test(value)) score += 1;
if (/[^A-Za-z0-9]/.test(value)) score += 1;

if (value.length < MIN_PASSWORD_LENGTH) {
return { score: 1, label: 'Too short', hint: `Use at least ${MIN_PASSWORD_LENGTH} characters` };
}
if (score <= 2) return { score: 2, label: 'Weak', hint: 'Add length, or a mix of characters' };
if (score === 3) return { score: 3, label: 'Fair', hint: '' };
if (score === 4) return { score: 4, label: 'Good', hint: '' };
Expand Down Expand Up @@ -149,8 +150,8 @@ export function VaultUnlock({ exists, onSetup, onUnlock, onRecover, onUnlocked }

let res;
if (mode === 'setup') {
if (password.length < MIN_PASSWORD_LENGTH) {
setError(`Use at least ${MIN_PASSWORD_LENGTH} characters`);
if (password.length === 0) {
setError('Enter a master password');
setBusy(false);
return;
}
Expand All @@ -166,8 +167,8 @@ export function VaultUnlock({ exists, onSetup, onUnlock, onRecover, onUnlocked }
return;
}
} else if (mode === 'recover') {
if (password.length < MIN_PASSWORD_LENGTH) {
setError(`Use at least ${MIN_PASSWORD_LENGTH} characters`);
if (password.length === 0) {
setError('Enter a master password');
setBusy(false);
return;
}
Expand Down
Loading