Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update password settings in browser extension popup CRUD (#883)
Leendert de Borstd10cc791481f
diff --git a/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx b/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsxindex 3c15bb392..add2fcaf4 100644--- a/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx@@ -110,7 +110,7 @@ export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(({};const inputClasses = `mt-1 block w-full rounded-md ${- error ? 'border-red-500' : 'border-gray-300 dark:border-gray-700'+ error ? 'border-red-500' : 'border-gray-300 dark:border-gray-600'} text-gray-900 sm:text-sm rounded-lg shadow-sm border focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 py-2 px-3`;// Add password visibility button if type is passworddiff --git a/apps/browser-extension/src/entrypoints/popup/components/PasswordConfigDialog.tsx b/apps/browser-extension/src/entrypoints/popup/components/PasswordConfigDialog.tsxindex 542b9dbea..007a3edba 100644--- a/apps/browser-extension/src/entrypoints/popup/components/PasswordConfigDialog.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/PasswordConfigDialog.tsx@@ -92,83 +92,12 @@ const PasswordConfigDialog: React.FC<IPasswordConfigDialogProps> = ({<div className="sm:flex sm:items-start"><div className="w-full mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left"><h3 className="text-lg font-medium leading-6 text-gray-900 dark:text-white mb-4">- {t('credentials.advancedPasswordOptions')}+ {t('credentials.changePasswordComplexity')}</h3>-- <div className="space-y-4">- {/* Character Type Checkboxes */}- <div className="space-y-3">- <div className="flex items-center">- <input- id="use-lowercase"- type="checkbox"- checked={settings.UseLowercase}- onChange={(e) => handleSettingChange('UseLowercase', e.target.checked)}- className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"- />- <label htmlFor="use-lowercase" className="ml-2 text-sm text-gray-700 dark:text-gray-300">- {t('credentials.includeLowercase')} (a-z)- </label>- </div>-- <div className="flex items-center">- <input- id="use-uppercase"- type="checkbox"- checked={settings.UseUppercase}- onChange={(e) => handleSettingChange('UseUppercase', e.target.checked)}- className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"- />- <label htmlFor="use-uppercase" className="ml-2 text-sm text-gray-700 dark:text-gray-300">- {t('credentials.includeUppercase')} (A-Z)- </label>- </div>-- <div className="flex items-center">- <input- id="use-numbers"- type="checkbox"- checked={settings.UseNumbers}- onChange={(e) => handleSettingChange('UseNumbers', e.target.checked)}- className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"- />- <label htmlFor="use-numbers" className="ml-2 text-sm text-gray-700 dark:text-gray-300">- {t('credentials.includeNumbers')} (0-9)- </label>- </div>-- <div className="flex items-center">- <input- id="use-special-chars"- type="checkbox"- checked={settings.UseSpecialChars}- onChange={(e) => handleSettingChange('UseSpecialChars', e.target.checked)}- className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"- />- <label htmlFor="use-special-chars" className="ml-2 text-sm text-gray-700 dark:text-gray-300">- {t('credentials.includeSpecialChars')} (!@#$%^&*)- </label>- </div>-- <div className="flex items-center">- <input- id="use-non-ambiguous"- type="checkbox"- checked={settings.UseNonAmbiguousChars}- onChange={(e) => handleSettingChange('UseNonAmbiguousChars', e.target.checked)}- className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"- />- <label htmlFor="use-non-ambiguous" className="ml-2 text-sm text-gray-700 dark:text-gray-300">- {t('credentials.avoidAmbiguousChars')} (avoid 0, O, l, I, etc.)- </label>- </div>- </div>+ <div className="space-y-4">{/* Password Preview */}<div className="mt-4">- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- {t('credentials.preview')}:- </label><div className="flex items-center gap-2"><inputtype="text"@@ -182,30 +111,101 @@ const PasswordConfigDialog: React.FC<IPasswordConfigDialogProps> = ({className="px-3 py-2 text-sm text-gray-500 dark:text-white bg-gray-200 hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-lg dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800"title={t('credentials.generateNewPreview')}>- <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <svg className="w-4 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg></button></div></div>++ {/* Character Type Toggle Buttons */}+ <div className="space-y-3">+ <div className="grid grid-cols-2 gap-2">+ {/* Lowercase Toggle */}+ <button+ type="button"+ onClick={() => handleSettingChange('UseLowercase', !settings.UseLowercase)}+ className={`flex items-center justify-center px-3 py-2 rounded-md text-sm font-medium transition-colors ${+ settings.UseLowercase+ ? 'bg-primary-600 text-white hover:bg-primary-700'+ : 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'+ }`}+ title={t('credentials.includeLowercase')}+ >+ <span className="font-mono text-base">a-z</span>+ </button>++ {/* Uppercase Toggle */}+ <button+ type="button"+ onClick={() => handleSettingChange('UseUppercase', !settings.UseUppercase)}+ className={`flex items-center justify-center px-3 py-2 rounded-md text-sm font-medium transition-colors ${+ settings.UseUppercase+ ? 'bg-primary-600 text-white hover:bg-primary-700'+ : 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'+ }`}+ title={t('credentials.includeUppercase')}+ >+ <span className="font-mono text-base">A-Z</span>+ </button>++ {/* Numbers Toggle */}+ <button+ type="button"+ onClick={() => handleSettingChange('UseNumbers', !settings.UseNumbers)}+ className={`flex items-center justify-center px-3 py-2 rounded-md text-sm font-medium transition-colors ${+ settings.UseNumbers+ ? 'bg-primary-600 text-white hover:bg-primary-700'+ : 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'+ }`}+ title={t('credentials.includeNumbers')}+ >+ <span className="font-mono text-base">0-9</span>+ </button>++ {/* Special Characters Toggle */}+ <button+ type="button"+ onClick={() => handleSettingChange('UseSpecialChars', !settings.UseSpecialChars)}+ className={`flex items-center justify-center px-3 py-2 rounded-md text-sm font-medium transition-colors ${+ settings.UseSpecialChars+ ? 'bg-primary-600 text-white hover:bg-primary-700'+ : 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'+ }`}+ title={t('credentials.includeSpecialChars')}+ >+ <span className="font-mono text-base">!@#</span>+ </button>+ </div>++ {/* Avoid Ambiguous Characters - Checkbox */}+ <div className="flex items-center">+ <input+ id="use-non-ambiguous"+ type="checkbox"+ checked={settings.UseNonAmbiguousChars}+ onChange={(e) => handleSettingChange('UseNonAmbiguousChars', e.target.checked)}+ className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600"+ />+ <label htmlFor="use-non-ambiguous" className="ml-2 text-sm text-gray-700 dark:text-gray-300">+ {t('credentials.avoidAmbiguousChars')}+ </label>+ </div>+ </div></div>{/* Action buttons */}<div className="mt-5 sm:mt-6 sm:flex sm:flex-row-reverse"><buttontype="button"- className="inline-flex w-full justify-center rounded-md bg-primary-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-primary-500 sm:ml-3 sm:w-auto"+ className="inline-flex w-full justify-center items-center gap-1 rounded-md bg-gray-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-500 sm:ml-3 sm:w-auto"onClick={handleSave}>+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 13l-3 3m0 0l-3-3m3 3V8m0 13a9 9 0 110-18 9 9 0 010 18z" />+ </svg>{t('common.use')}</button>- <button- type="button"- className="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:hover:bg-gray-600"- onClick={handleCancel}- >- {t('common.cancel')}- </button></div></div></div>diff --git a/apps/browser-extension/src/entrypoints/popup/components/PasswordField.tsx b/apps/browser-extension/src/entrypoints/popup/components/PasswordField.tsxindex 8d5d892e9..421801b3e 100644--- a/apps/browser-extension/src/entrypoints/popup/components/PasswordField.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/PasswordField.tsx@@ -51,10 +51,11 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({}}, [controlledShowPassword, onShowPasswordChange]);- // Update settings when initial settings change+ // Initialize settings only once when component mountsuseEffect(() => {setCurrentSettings({ ...initialSettings });- }, [initialSettings]);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, []); // Only run on mount to avoid resetting user changesconst generatePassword = useCallback((settings: PasswordSettings) => {try {@@ -72,11 +73,9 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({const newSettings = { ...currentSettings, Length: length };setCurrentSettings(newSettings);- // If there's already a password, regenerate it with the new length- if (value) {- generatePassword(newSettings);- }- }, [currentSettings, value, generatePassword]);+ // Always generate password when length changes+ generatePassword(newSettings);+ }, [currentSettings, generatePassword]);const handleRegeneratePassword = useCallback(() => {generatePassword(currentSettings);@@ -115,7 +114,7 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({value={value}onChange={(e) => onChange(e.target.value)}placeholder={placeholder}- className="outline-0 shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-l-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"+ className="outline-0 shadow-sm border border-gray-300 bg-gray-50 text-gray-900 sm:text-sm rounded-l-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"/></div><div className="flex">@@ -158,9 +157,22 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({<label htmlFor={`${id}-length`} className="text-sm font-medium text-gray-700 dark:text-gray-300">{t('credentials.passwordLength')}</label>- <span className="text-sm text-gray-600 dark:text-gray-400 font-mono">- {currentSettings.Length}- </span>+ <div className="flex items-center gap-2">+ <span className="text-sm text-gray-600 dark:text-gray-400 font-mono">+ {currentSettings.Length}+ </span>+ <button+ type="button"+ onClick={openConfigDialog}+ className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"+ title={t('credentials.changePasswordComplexity')}+ >+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />+ </svg>+ </button>+ </div></div><inputtype="range"@@ -171,17 +183,6 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({onChange={handleLengthChange}className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"/>-- {/* Advanced Options Link */}- <div className="mt-2">- <button- type="button"- onClick={openConfigDialog}- className="text-sm text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 underline cursor-pointer bg-transparent border-none p-0"- >- {t('credentials.changePasswordComplexity')}- </button>- </div></div>{/* Error Message */}diff --git a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsxindex be0146295..b05bc3798 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx@@ -1,7 +1,7 @@import { Buffer } from 'buffer';import { yupResolver } from '@hookform/resolvers/yup';-import React, { useState, useEffect, useCallback, useRef } from 'react';+import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';import { useForm } from 'react-hook-form';import { useTranslation } from 'react-i18next';import { useNavigate, useParams } from 'react-router-dom';@@ -75,12 +75,15 @@ const CredentialAddEdit: React.FC = () => {const { id } = useParams();const navigate = useNavigate();const dbContext = useDb();+ // If we received an ID, we're in edit mode+ const isEditMode = id !== undefined && id.length > 0;+const { executeVaultMutation, isLoading, syncStatus } = useVaultMutate();const [mode, setMode] = useState<CredentialMode>('random');const { setHeaderButtons } = useHeaderButtons();const { setIsInitialLoading } = useLoading();const [localLoading, setLocalLoading] = useState(true);- const [showPassword, setShowPassword] = useState(false);+ const [showPassword, setShowPassword] = useState(!isEditMode);const [showDeleteModal, setShowDeleteModal] = useState(false);const [attachments, setAttachments] = useState<Attachment[]>([]);const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);@@ -147,9 +150,6 @@ const CredentialAddEdit: React.FC = () => {return (): void => subscription.unsubscribe();}, [watch, persistFormValues]);- // If we received an ID, we're in edit mode- const isEditMode = id !== undefined && id.length > 0;-/*** Loads persisted form values from storage. This is used to keep track of form changes* and restore them when the page is reloaded. The browser extension popup will close@@ -229,7 +229,15 @@ const CredentialAddEdit: React.FC = () => {setIsInitialLoading(false);// Load persisted form values if they exist.- loadPersistedValues();+ loadPersistedValues().then(() => {+ // Generate default password if no persisted password exists+ if (!watch('Password')) {+ const passwordSettings = dbContext.sqliteClient!.getPasswordSettings();+ const passwordGenerator = CreatePasswordGenerator(passwordSettings);+ const defaultPassword = passwordGenerator.generateRandomPassword();+ setValue('Password', defaultPassword);+ }+ });return;}@@ -262,7 +270,7 @@ const CredentialAddEdit: React.FC = () => {console.error('Error loading credential:', err);setIsInitialLoading(false);}- }, [dbContext.sqliteClient, id, navigate, setIsInitialLoading, setValue, loadPersistedValues]);+ }, [dbContext.sqliteClient, id, navigate, setIsInitialLoading, setValue, loadPersistedValues, watch]);/*** Handle the delete button click.@@ -379,8 +387,8 @@ const CredentialAddEdit: React.FC = () => {}}, [setValue, watch]);- const getCurrentPasswordSettings = useCallback(() => {- return dbContext.sqliteClient!.getPasswordSettings();+ const initialPasswordSettings = useMemo(() => {+ return dbContext.sqliteClient?.getPasswordSettings();}, [dbContext.sqliteClient]);/**@@ -577,6 +585,13 @@ const CredentialAddEdit: React.FC = () => {<div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700"><h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white">{t('credentials.loginCredentials')}</h2><div className="space-y-4">+ <FormInput+ id="email"+ label={t('common.email')}+ value={watch('Alias.Email') ?? ''}+ onChange={(value) => setValue('Alias.Email', value)}+ error={errors.Alias?.Email?.message}+ /><UsernameFieldid="username"label={t('common.username')}@@ -585,23 +600,18 @@ const CredentialAddEdit: React.FC = () => {error={errors.Username?.message}onRegenerate={generateRandomUsername}/>- <PasswordField- id="password"- label={t('common.password')}- value={watch('Password') ?? ''}- onChange={(value) => setValue('Password', value)}- error={errors.Password?.message}- showPassword={showPassword}- onShowPasswordChange={setShowPassword}- initialSettings={getCurrentPasswordSettings()}- />- <FormInput- id="email"- label={t('common.email')}- value={watch('Alias.Email') ?? ''}- onChange={(value) => setValue('Alias.Email', value)}- error={errors.Alias?.Email?.message}- />+ {initialPasswordSettings && (+ <PasswordField+ id="password"+ label={t('common.password')}+ value={watch('Password') ?? ''}+ onChange={(value) => setValue('Password', value)}+ error={errors.Password?.message}+ showPassword={showPassword}+ onShowPasswordChange={setShowPassword}+ initialSettings={initialPasswordSettings}+ />+ )}</div></div>@@ -611,9 +621,17 @@ const CredentialAddEdit: React.FC = () => {<buttontype="button"onClick={handleGenerateRandomAlias}- className="w-full bg-primary-500 text-white py-2 px-4 rounded hover:bg-primary-600 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2"+ className="w-full bg-primary-500 text-white py-2 px-4 rounded hover:bg-primary-600 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 flex items-center justify-center gap-2">- {t('credentials.generateRandomAlias')}+ <svg className='w-5 h-5 inline-block' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>+ <circle cx="8" cy="8" r="1"/>+ <circle cx="16" cy="8" r="1"/>+ <circle cx="12" cy="12" r="1"/>+ <circle cx="8" cy="16" r="1"/>+ <circle cx="16" cy="16" r="1"/>+ </svg>+ <span>{t('credentials.generateRandomAlias')}</span></button><FormInputid="firstName"diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex c83ed92ce..04400a817 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -240,14 +240,12 @@"generateRandomPassword": "Generate random password","configurePassword": "Configure password","changePasswordComplexity": "Change password complexity",- "advancedPasswordOptions": "Advanced password options","passwordLength": "Password length","includeLowercase": "Include lowercase letters","includeUppercase": "Include uppercase letters","includeNumbers": "Include numbers","includeSpecialChars": "Include special characters",- "avoidAmbiguousChars": "Avoid ambiguous characters",- "preview": "Preview",+ "avoidAmbiguousChars": "Avoid ambiguous characters (o, 0, etc.)","generateNewPreview": "Generate new preview","generateRandomAlias": "Generate Random Alias","alias": "Alias",