Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make browser extension accept any char for PIN (#2498)
Leendert de Borst5da604f51558
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsxindex 94e443ad6..41afe0895 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx@@ -355,7 +355,7 @@ const Unlock: React.FC = () => {* Handle numpad button click*/const handleNumpadClick = (digit: string): void => {- if (pin.length < 8) {+ if (pin.length < pinLength) {handlePinChange(pin + digit);}};@@ -595,7 +595,7 @@ const Unlock: React.FC = () => {</div>{/* PIN Dots Display */}- <div className="flex justify-center gap-2 mb-4">+ <div className="flex flex-wrap justify-center gap-2 mb-4">{pinDots}</div>@@ -606,11 +606,9 @@ const Unlock: React.FC = () => {<inputref={inputRef}type="password"- inputMode="numeric"- pattern="[0-9]*"- maxLength={8}+ maxLength={pinLength}value={pin}- onChange={(e) => handlePinChange(e.target.value.replace(/\D/g, ''))}+ onChange={(e) => handlePinChange(e.target.value)}className="w-0 h-0 opacity-0 absolute"autoFocusaria-label={t('auth.pinInput')}diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsxindex d8ce7a9f1..9cd6808e9 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx@@ -18,6 +18,7 @@ import {setupPin,removeAndDisablePin,isValidPin,+ PIN_MAX_LENGTH,isPinLocked,InvalidPinFormatError} from '@/utils/PinUnlockService';@@ -279,11 +280,9 @@ const VaultUnlockSettings: React.FC = () => {<div className="mb-4"><inputtype="password"- inputMode="numeric"- pattern="[0-9]*"- maxLength={8}+ maxLength={PIN_MAX_LENGTH}value={newPin}- onChange={(e) => setNewPin(e.target.value.replace(/\D/g, ''))}+ onChange={(e) => setNewPin(e.target.value)}className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-center text-2xl tracking-widest"autoFocus/>@@ -309,11 +308,9 @@ const VaultUnlockSettings: React.FC = () => {<div className="mb-4"><inputtype="password"- inputMode="numeric"- pattern="[0-9]*"- maxLength={8}+ maxLength={PIN_MAX_LENGTH}value={confirmPin}- onChange={(e) => setConfirmPin(e.target.value.replace(/\D/g, ''))}+ onChange={(e) => setConfirmPin(e.target.value)}className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-center text-2xl tracking-widest"autoFocus/>diff --git a/apps/browser-extension/src/utils/PinUnlockService.ts b/apps/browser-extension/src/utils/PinUnlockService.tsindex ffc0c1021..10c53bf71 100644--- a/apps/browser-extension/src/utils/PinUnlockService.ts+++ b/apps/browser-extension/src/utils/PinUnlockService.ts@@ -9,13 +9,13 @@ import { browser, storage } from '#imports';/*** PinUnlockService - Handles PIN-based vault unlock*- * This service allows users to set a 6-8 digit PIN to unlock their vault instead+ * This service allows users to set a PIN (digits, letters or symbols) to unlock their vault instead* of entering their full master password. The Account Key* is encrypted with a key derived from the PIN and stored locally.** Security features:* - 4 failed attempts maximum before requiring full password- * - PIN must be 6-8 digits+ * - PIN must be 6-64 characters* - Encryption key derived using Argon2id (memory-hard, GPU-resistant)* - Extension ID pepper adds friction for naive attacks* - Failed attempts counter stored separately@@ -118,12 +118,17 @@ export async function getPinLength(): Promise<number | null> {}}+/** Minimum PIN length. */+export const PIN_MIN_LENGTH = 6;++/** Maximum PIN length. */+export const PIN_MAX_LENGTH = 64;+/**- * Validate PIN format (6-8 digits)+ * Validate PIN format (6-64 characters of any kind)*/export function isValidPin(pin: string): boolean {- const pinRegex = /^\d{6,8}$/;- return pinRegex.test(pin);+ return pin.length >= PIN_MIN_LENGTH && pin.length <= PIN_MAX_LENGTH;}/**@@ -153,7 +158,7 @@ export async function isPinLocked(): Promise<boolean> {* Setup PIN unlock* Encrypts the session's Account Key with the PIN and stores it*- * @param pin - The PIN to set (6-8 digits)+ * @param pin - The PIN to set (6-64 characters)* @param accountKey - The base64 Account Key to protect (VaultKeyService.getSessionAccountKey)*/export async function setupPin(pin: string, accountKey: string): Promise<void> {diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.jsonindex 007f826ab..5b8c7154b 100644--- a/core/i18n/locales/en.json+++ b/core/i18n/locales/en.json@@ -1495,7 +1495,7 @@"unlockMethod": {"confirmPin": "Confirm PIN","confirmPinDescription": "Enter your PIN again to confirm",- "enterNewPinDescription": "Enter a PIN code consisting of minimum 6 digits",+ "enterNewPinDescription": "Enter a PIN of at least 6 characters. Letters and symbols are allowed.","incorrectPin": "Incorrect PIN. {{attemptsRemaining}} attempts remaining.","incorrectPinSingular": "Incorrect PIN. 1 attempt remaining.","introText": "Choose how you want to unlock your vault. You can use your master password (always available) or set up a PIN code for faster access. After 3 failed PIN attempts, you'll need to use your master password.",