Skip to content

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

Refactor (#1340)

Leendert de Borst1751a4c242cb
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
index 6c51cb820..62b2357c0 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
@@ -581,9 +581,6 @@ class VaultStore(
return pin.getPinFailedAttempts()
}
- // Note: isPinLocked() removed - PIN is automatically disabled after max attempts
- // Use isPinEnabled() instead - it returns false when PIN is not set up OR was locked and cleared
-
/**
* Setup PIN unlock.
*/
diff --git a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
index a7c5f6d43..5901b7f9b 100644
--- a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
@@ -14,9 +14,7 @@ import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedScrollView } from '@/components/themed/ThemedScrollView';
import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
-import { RobustPressable } from '@/components/ui/RobustPressable';
import { AuthMethod, useAuth } from '@/context/AuthContext';
-import { useDb } from '@/context/DbContext';
/**
* Vault unlock settings screen.
@@ -24,7 +22,6 @@ import { useDb } from '@/context/DbContext';
export default function VaultUnlockSettingsScreen() : React.ReactNode {
const colors = useColors();
const { t } = useTranslation();
- const dbContext = useDb();
const [initialized, setInitialized] = useState(false);
const { setAuthMethods, getEnabledAuthMethods, getBiometricDisplayNameKey } = useAuth();
const [hasBiometrics, setHasBiometrics] = useState(false);
@@ -34,7 +31,6 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
// PIN state
const [pinEnabled, setPinEnabled] = useState(false);
- const [pinLocked, setPinLocked] = useState(false);
const [showPinSetup, setShowPinSetup] = useState(false);
const [pinSetupStep, setPinSetupStep] = useState(1);
const [newPin, setNewPin] = useState('');
@@ -73,7 +69,6 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
// Load PIN settings (locked state removed - automatically handled by native code)
const enabled = await isPinEnabled();
setPinEnabled(enabled);
- setPinLocked(false); // No longer tracking locked state
setInitialized(true);
} catch (error) {
@@ -188,7 +183,6 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
try {
await removeAndDisablePin();
setPinEnabled(false);
- setPinLocked(false);
Toast.show({
type: 'success',
text1: t('settings.vaultUnlockSettings.pinDisabled'),
@@ -228,26 +222,6 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
setPinError(null);
}, []);
- /**
- * Handle step 2 submit (confirm and save PIN).
- */
- const handleConfirmPinSubmit = useCallback(() : void => {
- if (confirmPin !== newPin) {
- setPinError(t('settings.vaultUnlockSettings.pinMismatch'));
- // Restart from step 1 on mismatch
- setTimeout(() => {
- setPinSetupStep(1);
- setNewPin('');
- setConfirmPin('');
- setPinError(null);
- }, 1000); // Show error for 1s before restarting
- return;
- }
-
- // PINs match, submit
- handlePinSetupSubmit(confirmPin);
- }, [confirmPin, newPin, t]);
-
/**
* Handle PIN setup submit.
*/
@@ -283,6 +257,26 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
}
}, [isBiometricsEnabled, setAuthMethods, t]);
+ /**
+ * Handle step 2 submit (confirm and save PIN).
+ */
+ const handleConfirmPinSubmit = useCallback(() : void => {
+ if (confirmPin !== newPin) {
+ setPinError(t('settings.vaultUnlockSettings.pinMismatch'));
+ // Restart from step 1 on mismatch
+ setTimeout(() => {
+ setPinSetupStep(1);
+ setNewPin('');
+ setConfirmPin('');
+ setPinError(null);
+ }, 1000); // Show error for 1s before restarting
+ return;
+ }
+
+ // PINs match, submit
+ handlePinSetupSubmit(confirmPin);
+ }, [confirmPin, newPin, t, handlePinSetupSubmit]);
+
const styles = StyleSheet.create({
button: {
alignItems: 'center',
@@ -444,29 +438,23 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {
{/* PIN option */}
<TouchableOpacity
style={styles.option}
- onPress={pinEnabled && !pinLocked ? handleDisablePin : handleEnablePin}
+ onPress={pinEnabled ? handleDisablePin : handleEnablePin}
>
<View style={styles.optionHeader}>
<View style={styles.optionHeaderLeft}>
- <ThemedText style={[styles.optionText, pinLocked && styles.disabledText]}>
+ <ThemedText style={[styles.optionText]}>
{t('settings.vaultUnlockSettings.pin')}
</ThemedText>
</View>
<View pointerEvents="none">
<Switch
- value={pinEnabled && !pinLocked}
- disabled={pinLocked}
+ value={pinEnabled}
/>
</View>
</View>
<ThemedText style={styles.helpText}>
{t('settings.vaultUnlockSettings.pinDescription')}
</ThemedText>
- {pinLocked && (
- <ThemedText style={styles.warningText}>
- {t('settings.vaultUnlockSettings.pinLocked')}
- </ThemedText>
- )}
</TouchableOpacity>
<View style={[styles.option, styles.optionLast]}>
diff --git a/apps/mobile-app/app/unlock.tsx b/apps/mobile-app/app/unlock.tsx
index 365fe91f2..84f4f3a28 100644
--- a/apps/mobile-app/app/unlock.tsx
+++ b/apps/mobile-app/app/unlock.tsx
@@ -7,9 +7,7 @@ import { useState, useEffect, useCallback } from 'react';
import { StyleSheet, View, TextInput, Alert, KeyboardAvoidingView, Platform, ScrollView, Dimensions, TouchableWithoutFeedback, Keyboard, Text, Pressable } from 'react-native';
import EncryptionUtility from '@/utils/EncryptionUtility';
-import {
- isPinEnabled,
-} from '@/utils/PinUnlockService';
+import { isPinEnabled } from '@/utils/PinUnlockService';
import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';
import { useColors } from '@/hooks/useColorScheme';
@@ -41,7 +39,6 @@ export default function UnlockScreen() : React.ReactNode {
// PIN unlock state
const [pinAvailable, setPinAvailable] = useState(false);
- const [showPasswordInput, setShowPasswordInput] = useState(false);
// Error state for password unlock
const [error, setError] = useState<string | null>(null);
@@ -60,7 +57,6 @@ export default function UnlockScreen() : React.ReactNode {
return params;
}, [logout, getEncryptionKeyDerivationParams]);
-
/**
* Handle PIN unlock using native UI.
* Falls back to showing password input on cancel.
@@ -70,13 +66,11 @@ export default function UnlockScreen() : React.ReactNode {
/*
* Show native PIN unlock UI
* This will handle the unlock internally and store the encryption key
- * The vault is now unlocked in native memory
*/
await NativeVaultManager.showPinUnlockUI();
/*
* Check if the vault is ready
- * The native code already unlocked it, so just verify it's available
*/
if (dbContext.dbAvailable) {
// Check if the vault is up to date, if not, redirect to the upgrade page.
@@ -91,12 +85,8 @@ export default function UnlockScreen() : React.ReactNode {
*/
router.replace('/initialize');
} else {
- /*
- * This shouldn't happen if unlock succeeded, but handle it
- * Show password input as fallback
- */
+ // If db is not available for whatever reason, fallback to password unlock.
setIsLoading(false);
- setShowPasswordInput(true);
Alert.alert(
t('common.error'),
t('auth.errors.incorrectPassword'),
@@ -111,14 +101,12 @@ export default function UnlockScreen() : React.ReactNode {
const error = err as { code?: string; message?: string };
if (error.code === 'USER_CANCELLED') {
// User cancelled PIN entry - show password input as fallback
- setShowPasswordInput(true);
return;
} else if (error.code === 'NOT_IMPLEMENTED') {
/*
* Native PIN UI not implemented on this platform (Android)
* Show password input and informative message
*/
- setShowPasswordInput(true);
Alert.alert(
t('common.info'),
'Native PIN unlock is currently only available on iOS. Android support coming soon.',
@@ -128,7 +116,6 @@ export default function UnlockScreen() : React.ReactNode {
} else if (error.code === 'PIN_DISABLED') {
// PIN was disabled due to too many attempts
setPinAvailable(false);
- setShowPasswordInput(true);
Alert.alert(
t('common.error'),
t('settings.vaultUnlockSettings.pinLocked'),
@@ -136,7 +123,6 @@ export default function UnlockScreen() : React.ReactNode {
);
} else {
// Other errors - show password input as fallback
- setShowPasswordInput(true);
console.error('PIN unlock failed:', err);
Alert.alert(
t('common.error'),
@@ -144,9 +130,6 @@ export default function UnlockScreen() : React.ReactNode {
[{ text: t('common.ok'), style: 'default' }]
);
}
- } else {
- // Unknown error - show password input as fallback
- setShowPasswordInput(true);
}
}
}, [dbContext, t, setPinAvailable]);
@@ -171,15 +154,13 @@ export default function UnlockScreen() : React.ReactNode {
/*
* If PIN is enabled, automatically try PIN unlock first
* Show loading state, then launch native PIN UI
- * Only show password input if user cancels or PIN is not available
+ * If user cancels or PIN is not available, loading stops and password input shows
*/
if (pinEnabled) {
setIsLoading(true);
await handlePinUnlock();
- } else {
- // No PIN available, show password input immediately
- setShowPasswordInput(true);
}
+ // If no PIN, isLoading stays false and password input shows automatically
};
fetchConfigAndUnlock();
@@ -423,7 +404,7 @@ export default function UnlockScreen() : React.ReactNode {
// Render password mode or loading
return (
<ThemedView style={styles.container}>
- {isLoading || !showPasswordInput ? (
+ {isLoading ? (
<View style={styles.loadingContainer}>
<LoadingIndicator status={t('app.status.unlockingVault')} />
</View>
@@ -513,7 +494,6 @@ export default function UnlockScreen() : React.ReactNode {
<Pressable
style={styles.linkButton}
onPress={() => {
- setShowPasswordInput(false);
setIsLoading(true);
handlePinUnlock();
}}
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index 186abfda3..03089441e 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -306,8 +306,6 @@
"confirmPinDescription": "Re-enter your PIN to confirm",
"pinMismatch": "PINs do not match. Please try again.",
"pinLocked": "PIN locked after too many failed attempts. Please use your master password.",
- "incorrectPin": "Incorrect PIN. {{attemptsRemaining}} attempts remaining.",
- "incorrectPinSingular": "Incorrect PIN. 1 attempt remaining.",
"passwordHelp": "Re-enter your full master password to unlock your vault. This is always enabled as fallback option.",
"keystoreIOS": "iOS Keychain",
"keystoreAndroid": "Android Keystore"