Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update vault unlock settings and pin unlock UI (#1338)
Leendert de Borstfb28827f15e5
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsxindex c29878df8..8dcd0baed 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx@@ -46,7 +46,7 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ routes, headerButtons, meheight: 'calc(100% - 120px)',}}>- <div className="p-4 mb-16">+ <div className="px-4 pb-4 pt-2 mb-16">{message && (<p className="text-red-500 mb-4">{message}</p>)}diff --git a/apps/browser-extension/src/entrypoints/popup/components/Unlock/UsernameAvatar.tsx b/apps/browser-extension/src/entrypoints/popup/components/Unlock/UsernameAvatar.tsxnew file mode 100644index 000000000..0c304219c--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Unlock/UsernameAvatar.tsx@@ -0,0 +1,34 @@+import React from 'react';+import { useTranslation } from 'react-i18next';++import { useAuth } from '@/entrypoints/popup/context/AuthContext';++/**+ * Username avatar component that shows the avatar and username.+ */+const UsernameAvatar: React.FC = () => {+ const { t } = useTranslation();+ const { username } = useAuth();++ return (+ <div className="flex items-center space-x-3 mb-6">+ <div className="flex-shrink-0">+ <div className="w-10 h-10 rounded-full bg-primary-100 dark:bg-primary-900 flex items-center justify-center">+ <span className="text-primary-600 dark:text-primary-400 text-lg font-medium">+ {username?.[0]?.toUpperCase() || '?'}+ </span>+ </div>+ </div>+ <div>+ <p className="font-medium text-gray-900 dark:text-white">+ {username}+ </p>+ <p className="text-sm text-gray-500 dark:text-gray-400">+ {t('auth.loggedIn')}+ </p>+ </div>+ </div>+ );+};++export default UsernameAvatar;\ No newline at end of filediff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsxindex a9d60bb63..08e2b75d8 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx@@ -7,6 +7,7 @@ import { useNavigate } from 'react-router-dom';import Button from '@/entrypoints/popup/components/Button';import HeaderButton from '@/entrypoints/popup/components/HeaderButton';import { HeaderIcon, HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';+import UsernameAvatar from '@/entrypoints/popup/components/Unlock/UsernameAvatar';import { useApp } from '@/entrypoints/popup/context/AppContext';import { useAuth } from '@/entrypoints/popup/context/AuthContext';import { useDb } from '@/entrypoints/popup/context/DbContext';@@ -385,6 +386,9 @@ const Unlock: React.FC = () => {return (<div ref={containerRef} className="flex flex-col items-center justify-center p-4 bg-gray-50 dark:bg-gray-900"><div className="w-full max-w-md">+ {/* User Avatar and Username Section */}+ <UsernameAvatar />+{/* Logo */}<div className="text-center mb-4"><h1 className="text-xl font-bold text-gray-900 dark:text-white mb-1">@@ -488,23 +492,7 @@ const Unlock: React.FC = () => {<div><form onSubmit={handlePasswordSubmit} className="bg-white dark:bg-gray-700 w-full shadow-md rounded px-8 pt-6 pb-8 mb-4">{/* User Avatar and Username Section */}- <div className="flex items-center space-x-3 mb-6">- <div className="flex-shrink-0">- <div className="w-10 h-10 rounded-full bg-primary-100 dark:bg-primary-900 flex items-center justify-center">- <span className="text-primary-600 dark:text-primary-400 text-lg font-medium">- {authContext.username?.[0]?.toUpperCase() || '?'}- </span>- </div>- </div>- <div>- <p className="font-medium text-gray-900 dark:text-white">- {authContext.username}- </p>- <p className="text-sm text-gray-500 dark:text-gray-400">- {t('auth.loggedIn')}- </p>- </div>- </div>+ <UsernameAvatar />{/* Instruction Title */}<h2 className="text-xl font-semibold text-gray-900 dark:text-white mb-4">diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsxindex 92782e227..c0d8c2657 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx@@ -261,18 +261,8 @@ const Settings: React.FC = () => {className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">- <svg- className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400"- fill="none"- stroke="currentColor"- strokeWidth={2}- viewBox="0 0 24 24"- >- <path- strokeLinecap="round"- strokeLinejoin="round"- d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"- />+ <svg className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" /></svg><span className="text-gray-900 dark:text-white">{t('settings.unlockMethod.title')}</span></div>diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsxindex 6fd278ba4..bdbd2984e 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/VaultUnlockSettings.tsx@@ -165,198 +165,188 @@ const VaultUnlockSettings: React.FC = () => {return (- <div className="space-y-4">- {/* Error/Success Messages */}- {error && (- <div className="p-3 bg-red-100 dark:bg-red-900/30 border border-red-300 dark:border-red-700 rounded-md text-red-800 dark:text-red-300 text-sm">- {error}- </div>- )}- {success && (- <div className="p-3 bg-green-100 dark:bg-green-900/30 border border-green-300 dark:border-green-700 rounded-md text-green-800 dark:text-green-300 text-sm">- {success}- </div>- )}-- {/* Locked Warning */}- {isLocked && (- <div className="p-3 bg-yellow-100 dark:bg-yellow-900/30 border border-yellow-300 dark:border-yellow-700 rounded-md text-yellow-800 dark:text-yellow-300 text-sm">- {t('settings.unlockMethod.pinLocked')}- </div>- )}+ <>+ <div>+ <p className="text-sm text-gray-600 dark:text-gray-400">+ {t('settings.unlockMethod.helpText')}+ </p>+ </div>+ <div className="mt-6">+ {/* Error/Success Messages */}+ {error && (+ <div className="mb-4 p-3 bg-red-100 dark:bg-red-900/30 border border-red-300 dark:border-red-700 rounded-md text-red-800 dark:text-red-300 text-sm">+ {error}+ </div>+ )}+ {success && (+ <div className="mb-4 p-3 bg-green-100 dark:bg-green-900/30 border border-green-300 dark:border-green-700 rounded-md text-green-800 dark:text-green-300 text-sm">+ {success}+ </div>+ )}- {/* PIN Code option */}- <section>- <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">- <div className="p-4">- <div className="flex items-center justify-between">- <div className="flex items-center">- <svg className="w-5 h-5 mr-2 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />- </svg>- <div>- <div className="flex items-center">- <p className="font-medium text-gray-900 dark:text-white">{t('settings.unlockMethod.pin')}</p>- <HelpModal- titleKey="settings.unlockMethod.pin"- contentKey="settings.unlockMethod.helpText"- className="ml-2"- />+ {/* Locked Warning */}+ {isLocked && (+ <div className="p-3 bg-yellow-100 dark:bg-yellow-900/30 border border-yellow-300 dark:border-yellow-700 rounded-md text-yellow-800 dark:text-yellow-300 text-sm">+ {t('settings.unlockMethod.pinLocked')}+ </div>+ )}++ {/* PIN Code option */}+ <section>+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="p-4">+ <div className="flex items-center justify-between">+ <div className="flex items-center">+ <svg className="w-5 h-5 mr-2 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />+ </svg>+ <div>+ <div className="flex items-center">+ <p className="font-medium text-gray-900 dark:text-white">{t('settings.unlockMethod.pin')}</p>+ </div>+ <p className="text-sm mt-1 text-gray-600 dark:text-gray-400">+ {t('settings.unlockMethod.pinDescription')}+ </p></div>- <p className="text-sm mt-1 text-gray-600 dark:text-gray-400">- {t('settings.unlockMethod.pinDescription')}- </p></div>+ <button+ onClick={pinEnabled && !isLocked ? handleDisablePin : handleEnablePin}+ className={`px-4 py-2 rounded-md transition-colors ${+ pinEnabled && !isLocked+ ? 'bg-green-500 hover:bg-green-600 text-white'+ : 'bg-red-500 hover:bg-red-600 text-white'+ }`}+ >+ {pinEnabled && !isLocked ? t('settings.enabled') : t('settings.disabled')}+ </button></div>- <button- onClick={pinEnabled && !isLocked ? handleDisablePin : handleEnablePin}- className={`px-4 py-2 rounded-md transition-colors ${- pinEnabled && !isLocked- ? 'bg-green-500 hover:bg-green-600 text-white'- : 'bg-red-500 hover:bg-red-600 text-white'- }`}- >- {pinEnabled && !isLocked ? t('settings.enabled') : t('settings.disabled')}- </button></div>-- {/* Reset PIN if locked */}- {isLocked && (- <div className="mt-4">- <Button onClick={handleEnablePin} className="w-full">- {t('settings.unlockMethod.resetPin')}- </Button>- </div>- )}</div>- </div>- </section>-- {/* Master Password option (always enabled, cannot be toggled) */}- <section>- <div className="bg-gray-50 dark:bg-gray-700/30 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 opacity-75">- <div className="p-4">- <div className="flex items-center justify-between">- <div className="flex items-center">- <svg className="w-5 h-5 mr-2 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />- </svg>- <div>- <p className="font-medium text-gray-900 dark:text-white">{t('settings.unlockMethod.password')}</p>- <p className="text-sm mt-1 text-gray-600 dark:text-gray-400">- {t('settings.unlockMethod.passwordDescription')}- </p>+ </section>++ {/* Master Password option (always enabled, cannot be toggled) */}+ <section className="mt-4">+ <div className="bg-gray-50 dark:bg-gray-700/30 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="p-4">+ <div className="flex items-center justify-between">+ <div className="flex items-center">+ <svg className="w-5 h-5 mr-2 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />+ </svg>+ <div>+ <p className="font-medium text-gray-900 dark:text-white">{t('settings.unlockMethod.password')}</p>+ </div>+ </div>+ <div className="px-4 py-2 rounded-md bg-gray-300 text-gray-600 dark:bg-gray-600 dark:text-gray-300 cursor-not-allowed">+ {t('settings.enabled')}</div>- </div>- <div className="px-4 py-2 rounded-md bg-gray-300 text-gray-600 dark:bg-gray-600 dark:text-gray-300 cursor-not-allowed">- {t('settings.enabled')}</div></div></div>- </div>- </section>+ </section>- {/* PIN Setup Modal */}- {showPinSetup && (- <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">- <div className="bg-white dark:bg-gray-800 rounded-lg p-6 max-w-md w-full mx-4 relative">- {/* Cancel button in top right corner */}- <button- type="button"- onClick={() => {- setShowPinSetup(false);- setPinSetupStep(1);- setNewPin('');- setConfirmPin('');- setError(null);- }}- className="absolute top-4 right-4 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 transition-colors"- aria-label="Cancel"- >- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />- </svg>- </button>+ {/* PIN Setup Modal */}+ {showPinSetup && (+ <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">+ <div className="bg-white dark:bg-gray-800 rounded-lg p-6 max-w-md w-full mx-4 relative">+ {/* Cancel button in top right corner */}+ <button+ type="button"+ onClick={() => {+ setShowPinSetup(false);+ setPinSetupStep(1);+ setNewPin('');+ setConfirmPin('');+ setError(null);+ }}+ className="absolute top-4 right-4 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 transition-colors"+ aria-label="Cancel"+ >+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>- {/* Step 1: Enter PIN */}- {pinSetupStep === 1 && (- <>- <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4 pr-8">- {t('settings.unlockMethod.setupPin')}- </h3>- <p className="text-sm text-gray-600 dark:text-gray-400 mb-4">- {t('settings.unlockMethod.enterNewPinDescription')}- </p>- <form onSubmit={handlePinSetupNext}>- <div className="mb-4">- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- {t('settings.unlockMethod.enterNewPin')}- </label>- <input- type="password"- inputMode="numeric"- pattern="[0-9]*"- maxLength={8}- value={newPin}- onChange={(e) => setNewPin(e.target.value.replace(/\D/g, ''))}- placeholder={t('settings.unlockMethod.pinPlaceholder')}- 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- />- </div>- {error && (- <div className="mb-4 text-red-500 dark:text-red-400 text-sm">- {error}+ {/* Step 1: Enter PIN */}+ {pinSetupStep === 1 && (+ <>+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4 pr-8">+ {t('settings.unlockMethod.setupPin')}+ </h3>+ <p className="text-sm text-gray-600 dark:text-gray-400 mb-4">+ {t('settings.unlockMethod.enterNewPinDescription')}+ </p>+ <form onSubmit={handlePinSetupNext}>+ <div className="mb-4">+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ {t('settings.unlockMethod.enterNewPin')}+ </label>+ <input+ type="password"+ inputMode="numeric"+ pattern="[0-9]*"+ maxLength={8}+ value={newPin}+ onChange={(e) => setNewPin(e.target.value.replace(/\D/g, ''))}+ placeholder={t('settings.unlockMethod.pinPlaceholder')}+ 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+ /></div>- )}- <Button type="submit">- {t('settings.unlockMethod.next')}- </Button>- </form>- </>- )}-- {/* Step 2: Confirm PIN */}- {pinSetupStep === 2 && (- <>- <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4 pr-8">- {t('settings.unlockMethod.confirmPinTitle')}- </h3>- <p className="text-sm text-gray-600 dark:text-gray-400 mb-4">- {t('settings.unlockMethod.confirmPinDescription')}- </p>- <form onSubmit={handlePinSetupSubmit}>- <div className="mb-4">- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- {t('settings.unlockMethod.confirmPin')}- </label>- <input- type="password"- inputMode="numeric"- pattern="[0-9]*"- maxLength={8}- value={confirmPin}- onChange={(e) => setConfirmPin(e.target.value.replace(/\D/g, ''))}- placeholder={t('settings.unlockMethod.pinPlaceholder')}- 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- />- </div>- {error && (- <div className="mb-4 text-red-500 dark:text-red-400 text-sm">- {error}+ {error && (+ <div className="mb-4 text-red-500 dark:text-red-400 text-sm">+ {error}+ </div>+ )}+ <Button type="submit">+ {t('settings.unlockMethod.next')}+ </Button>+ </form>+ </>+ )}++ {/* Step 2: Confirm PIN */}+ {pinSetupStep === 2 && (+ <>+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4 pr-8">+ {t('settings.unlockMethod.confirmPinTitle')}+ </h3>+ <p className="text-sm text-gray-600 dark:text-gray-400 mb-4">+ {t('settings.unlockMethod.confirmPinDescription')}+ </p>+ <form onSubmit={handlePinSetupSubmit}>+ <div className="mb-4">+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ {t('settings.unlockMethod.confirmPin')}+ </label>+ <input+ type="password"+ inputMode="numeric"+ pattern="[0-9]*"+ maxLength={8}+ value={confirmPin}+ onChange={(e) => setConfirmPin(e.target.value.replace(/\D/g, ''))}+ placeholder={t('settings.unlockMethod.pinPlaceholder')}+ 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+ /></div>- )}- <Button type="submit">- {t('settings.unlockMethod.confirm')}- </Button>- </form>- </>- )}+ {error && (+ <div className="mb-4 text-red-500 dark:text-red-400 text-sm">+ {error}+ </div>+ )}+ <Button type="submit">+ {t('settings.unlockMethod.confirm')}+ </Button>+ </form>+ </>+ )}+ </div></div>- </div>- )}- </div>+ )}+ </div>+ </>);};diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex e73d453af..0b9d40e09 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -394,9 +394,8 @@"unlockMethod": {"title": "Vault Unlock Method","methods": "Unlock Methods",- "helpText": "Choose how you want to unlock your vault. You can use your master password (always available) or set up a quick 4-8 digit PIN for faster access. After 4 failed PIN attempts, you'll need to use your master password.",+ "helpText": "Choose how you want to unlock your vault. You can use your master password (always available) or set up a quick 4-8 digit PIN for faster access. After 3 failed PIN attempts, you'll need to use your master password.","password": "Master Password",- "passwordDescription": "Always available as fallback","alwaysEnabled": "Always Enabled","enabled": "Enabled","disabled": "Disabled",@@ -407,7 +406,6 @@"pinLockedDescription": "PIN locked after too many failed attempts","enablePin": "Enable PIN Unlock","disablePin": "Disable PIN Unlock",- "resetPin": "Reset PIN","testPin": "Test PIN","setupPin": "Setup PIN Code","setupPinDescription": "Enter a 4-8 digit PIN that you'll use to quickly unlock your vault. Your vault encryption key will be encrypted with this PIN and stored locally.",@@ -431,7 +429,7 @@"testError": "Incorrect PIN.","loadError": "Failed to load unlock method settings.","unlockVaultFirst": "Please unlock your vault with your master password first.",- "pinLocked": "PIN unlock has been disabled after 4 failed attempts. Please use your master password to unlock your vault.",+ "pinLocked": "PIN unlock has been disabled. Please use your master password to unlock your vault.","failedAttempts": "failed attempts"}},diff --git a/apps/browser-extension/src/utils/PinUnlockService.ts b/apps/browser-extension/src/utils/PinUnlockService.tsindex e5afafe3b..587e224e4 100644--- a/apps/browser-extension/src/utils/PinUnlockService.ts+++ b/apps/browser-extension/src/utils/PinUnlockService.ts@@ -17,7 +17,7 @@ const PIN_ENCRYPTED_KEY_KEY = 'aliasvault_pin_encrypted_key';const PIN_SALT_KEY = 'aliasvault_pin_salt';const PIN_LENGTH_KEY = 'aliasvault_pin_length';const PIN_FAILED_ATTEMPTS_KEY = 'aliasvault_pin_failed_attempts';-const MAX_PIN_ATTEMPTS = 4;+const MAX_PIN_ATTEMPTS = 3;const MIN_PIN_LENGTH = 4;const MAX_PIN_LENGTH = 8;