Skip to content

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

Tweak browser extension and mobile app unlock wrong password error

Leendert de Borstbf1154962e91
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
index e17f07e4c..4e25222e3 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -31,7 +31,7 @@ import {
resetFailedAttempts,
unlockWithPin
} from '@/utils/PinUnlockService';
-import { hasErrorCode, getErrorMessage } from '@/utils/types/errors/AppErrorCodes';
+import { hasErrorCode, getErrorMessage, extractErrorCode, AppErrorCode } from '@/utils/types/errors/AppErrorCodes';
import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';
import type { MobileLoginResult } from '@/utils/types/messaging/MobileLoginResult';
@@ -304,8 +304,14 @@ const Unlock: React.FC = () => {
if (err instanceof VaultVersionIncompatibleError) {
await app.logout(err.message);
} else if (hasErrorCode(err)) {
- // Error contains an error code (E-XXX), show the formatted message as-is
- setError(getErrorMessage(err, t('common.errors.wrongPassword')));
+ // Check if it's a decryption failure (E-203): this means wrong password
+ const errorCode = extractErrorCode(getErrorMessage(err, ''));
+ if (errorCode === AppErrorCode.VAULT_DECRYPT_FAILED) {
+ setError(t('common.errors.wrongPassword'));
+ } else {
+ // Other error codes, show the formatted message as-is
+ setError(getErrorMessage(err, t('common.errors.wrongPassword')));
+ }
} else {
setError(t('common.errors.wrongPassword'));
}
@@ -418,9 +424,17 @@ const Unlock: React.FC = () => {
setError(t('settings.unlockMethod.invalidPinFormat'));
setPin('');
} else if (hasErrorCode(err)) {
- // Error contains an error code (E-XXX), show the formatted message as-is
- console.error('PIN unlock failed:', err);
- setError(getErrorMessage(err, t('common.errors.unknownErrorTryAgain')));
+ // Check if it's a decryption failure, this means wrong PIN
+ const errorCode = extractErrorCode(getErrorMessage(err, ''));
+ if (errorCode === AppErrorCode.VAULT_DECRYPT_FAILED) {
+ // Decryption failed during PIN unlock = wrong PIN, treat as incorrect PIN
+ console.error('PIN unlock failed (decryption error):', err);
+ setError(t('settings.unlockMethod.incorrectPin', { attemptsRemaining: 3 }));
+ } else {
+ // Other error codes: show the formatted message as-is
+ console.error('PIN unlock failed:', err);
+ setError(getErrorMessage(err, t('common.errors.unknownErrorTryAgain')));
+ }
setPin('');
} else {
console.error('PIN unlock failed:', err);
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt
index c8dab3087..822dfd859 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt
@@ -248,7 +248,7 @@ class VaultCrypto(
val decrypted = cipher.doFinal(encryptedContent)
decryptedResult = String(decrypted, Charsets.UTF_8)
} catch (e: Exception) {
- error = e
+ error = AppError.VaultDecryptFailed(cause = e)
Log.e(TAG, "Error decrypting data", e)
} finally {
latch.countDown()
diff --git a/apps/mobile-app/app/unlock.tsx b/apps/mobile-app/app/unlock.tsx
index 07afe3774..d15cd3618 100644
--- a/apps/mobile-app/app/unlock.tsx
+++ b/apps/mobile-app/app/unlock.tsx
@@ -7,7 +7,7 @@ import { useState, useEffect, useCallback } from 'react';
import { StyleSheet, View, TextInput, KeyboardAvoidingView, Platform, ScrollView, Dimensions, Text, Pressable } from 'react-native';
import EncryptionUtility from '@/utils/EncryptionUtility';
-import { getAppErrorCode, getErrorTranslationKey, formatErrorWithCode } from '@/utils/types/errors/AppErrorCodes';
+import { AppErrorCode, getAppErrorCode, getErrorTranslationKey, formatErrorWithCode } from '@/utils/types/errors/AppErrorCodes';
import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';
import { useColors } from '@/hooks/useColorScheme';
@@ -166,12 +166,18 @@ export default function UnlockScreen() : React.ReactNode {
// Try to extract error code from the error
const errorCode = getAppErrorCode(err);
- if (errorCode) {
+
+ /*
+ * During unlock, VAULT_DECRYPT_FAILED indicates wrong password.
+ * This is thrown when decryption fails due to incorrect encryption key.
+ */
+ if (!errorCode || errorCode === AppErrorCode.VAULT_DECRYPT_FAILED) {
+ // Treat as incorrect password
+ showAlert(t('common.error'), t('auth.errors.incorrectPassword'));
+ } else {
+ // Other error codes: show the formatted message with raw error code
const translationKey = getErrorTranslationKey(errorCode);
showAlert(t('common.error'), formatErrorWithCode(t(translationKey), errorCode));
- } else {
- // Fallback to incorrect password for unknown errors (likely password mismatch)
- showAlert(t('common.error'), t('auth.errors.incorrectPassword'));
}
} finally {
setIsLoading(false);