Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Only overwrite email/username/pass if values were autogenerated during alias generation (#1235)

Leendert de Borst03b65a63ba51
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/CredentialAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/CredentialAddEdit.tsx
index 7169f9b21..bcf0da2df 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/CredentialAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/CredentialAddEdit.tsx
@@ -90,6 +90,13 @@ const CredentialAddEdit: React.FC = () => {
const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);
const webApi = useWebApi();
+ // Track last generated values to avoid overwriting manual entries
+ const [lastGeneratedValues, setLastGeneratedValues] = useState<{
+ username: string | null;
+ password: string | null;
+ email: string | null;
+ }>({ username: null, password: null, email: null });
+
const serviceNameRef = useRef<HTMLInputElement>(null);
const { handleSubmit, setValue, watch, formState: { errors } } = useForm<Credential>({
@@ -331,8 +338,13 @@ const CredentialAddEdit: React.FC = () => {
const defaultEmailDomain = dbContext.sqliteClient!.getDefaultEmailDomain(privateEmailDomains, publicEmailDomains);
const email = defaultEmailDomain ? `${identity.emailPrefix}@${defaultEmailDomain}` : identity.emailPrefix;
- // Set email based on mode: always for new credentials, only if empty for existing ones
- if (!isEditMode || !watch('Alias.Email')) {
+ // Check current values
+ const currentUsername = watch('Username') ?? '';
+ const currentPassword = watch('Password') ?? '';
+ const currentEmail = watch('Alias.Email') ?? '';
+
+ // Only overwrite email if it's empty or matches the last generated value
+ if (!currentEmail || currentEmail === lastGeneratedValues.email) {
setValue('Alias.Email', email);
}
setValue('Alias.FirstName', identity.firstName);
@@ -341,21 +353,23 @@ const CredentialAddEdit: React.FC = () => {
setValue('Alias.Gender', identity.gender);
setValue('Alias.BirthDate', IdentityHelperUtils.normalizeBirthDateForDisplay(identity.birthDate.toISOString()));
- // In edit mode, preserve existing username and password if they exist
- if (isEditMode && watch('Username')) {
- // Keep the existing username in edit mode, so don't do anything here.
- } else {
- // Use the newly generated username
+ // Only overwrite username if it's empty or matches the last generated value
+ if (!currentUsername || currentUsername === lastGeneratedValues.username) {
setValue('Username', identity.nickName);
}
- if (isEditMode && watch('Password')) {
- // Keep the existing password in edit mode, so don't do anything here.
- } else {
- // Use the newly generated password
+ // Only overwrite password if it's empty or matches the last generated value
+ if (!currentPassword || currentPassword === lastGeneratedValues.password) {
setValue('Password', password);
}
- }, [isEditMode, watch, setValue, initializeGenerators, dbContext]);
+
+ // Update tracking with new generated values
+ setLastGeneratedValues({
+ username: identity.nickName,
+ password: password,
+ email: email
+ });
+ }, [watch, setValue, initializeGenerators, dbContext, lastGeneratedValues, setLastGeneratedValues]);
/**
* Clear all alias fields.
@@ -403,12 +417,17 @@ const CredentialAddEdit: React.FC = () => {
};
const username = usernameEmailGenerator.generateUsername(identity);
- setValue('Username', username);
+ const currentUsername = watch('Username') ?? '';
+ // Only overwrite username if it's empty or matches the last generated value
+ if (!currentUsername || currentUsername === lastGeneratedValues.username) {
+ setValue('Username', username);
+ // Update the tracking for username
+ setLastGeneratedValues(prev => ({ ...prev, username: username }));
+ }
} catch (error) {
console.error('Error generating random username:', error);
}
- }, [setValue, watch]);
-
+ }, [setValue, watch, lastGeneratedValues, setLastGeneratedValues]);
/**
* Handle form submission.
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index 914fe400d..6e51235c5 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -58,6 +58,13 @@ export default function AddEditCredentialScreen() : React.ReactNode {
const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);
const { t } = useTranslation();
+ // Track last generated values to avoid overwriting manual entries
+ const [lastGeneratedValues, setLastGeneratedValues] = useState<{
+ username: string | null;
+ password: string | null;
+ email: string | null;
+ }>({ username: null, password: null, email: null });
+
const { control, handleSubmit, setValue, watch } = useForm<Credential>({
resolver: yupResolver(createCredentialSchema(t)) as Resolver<Credential>,
defaultValues: {
@@ -189,8 +196,13 @@ export default function AddEditCredentialScreen() : React.ReactNode {
const defaultEmailDomain = await dbContext.sqliteClient!.getDefaultEmailDomain();
const email = defaultEmailDomain ? `${identity.emailPrefix}@${defaultEmailDomain}` : identity.emailPrefix;
- // Set email based on mode: always for new credentials, only if empty for existing ones
- if (!isEditMode || !watch('Alias.Email')) {
+ // Check current values
+ const currentUsername = watch('Username') ?? '';
+ const currentPassword = watch('Password') ?? '';
+ const currentEmail = watch('Alias.Email') ?? '';
+
+ // Only overwrite email if it's empty or matches the last generated value
+ if (!currentEmail || currentEmail === lastGeneratedValues.email) {
setValue('Alias.Email', email);
}
setValue('Alias.FirstName', identity.firstName);
@@ -199,23 +211,25 @@ export default function AddEditCredentialScreen() : React.ReactNode {
setValue('Alias.Gender', identity.gender);
setValue('Alias.BirthDate', IdentityHelperUtils.normalizeBirthDateForDisplay(identity.birthDate.toISOString()));
- // In edit mode, preserve existing username and password if they exist
- if (isEditMode && watch('Username')) {
- // Keep the existing username in edit mode, so don't do anything here.
- } else {
- // Use the newly generated username
+ // Only overwrite username if it's empty or matches the last generated value
+ if (!currentUsername || currentUsername === lastGeneratedValues.username) {
setValue('Username', identity.nickName);
}
- if (isEditMode && watch('Password')) {
- // Keep the existing password in edit mode, so don't do anything here.
- } else {
- // Use the newly generated password
+ // Only overwrite password if it's empty or matches the last generated value
+ if (!currentPassword || currentPassword === lastGeneratedValues.password) {
setValue('Password', password);
// Make password visible when newly generated
setIsPasswordVisible(true);
}
- }, [isEditMode, watch, setValue, setIsPasswordVisible, initializeGenerators, dbContext.sqliteClient]);
+
+ // Update tracking with new generated values
+ setLastGeneratedValues({
+ username: identity.nickName,
+ password: password,
+ email: email
+ });
+ }, [watch, setValue, setIsPasswordVisible, initializeGenerators, dbContext.sqliteClient, lastGeneratedValues, setLastGeneratedValues]);
/**
* Clear all alias fields.
@@ -379,8 +393,13 @@ export default function AddEditCredentialScreen() : React.ReactNode {
// Generate identity with gender preference
const identity = identityGenerator.generateRandomIdentity(genderPreference);
- // Set the username to the identity's nickname
- setValue('Username', identity.nickName);
+ // Only overwrite username if it's empty or matches the last generated value
+ const currentUsername = watch('Username') ?? '';
+ if (!currentUsername || currentUsername === lastGeneratedValues.username) {
+ setValue('Username', identity.nickName);
+ // Update the tracking for username
+ setLastGeneratedValues(prev => ({ ...prev, username: identity.nickName }));
+ }
} catch (error) {
console.error('Error generating random username:', error);
Toast.show({