Skip to content

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

Tweak iOS native pin unlock view flow (#1340)

Leendert de Borst7b6170e927ea
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index 79900e0eb..ed1f2840d 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -268,6 +268,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
)
},
cancelHandler: { [weak self] in
+ // Passkey registration - just cancel on any dismissal
self?.extensionContext.cancelRequest(withError: NSError(
domain: ASExtensionErrorDomain,
code: ASExtensionError.userCanceled.rawValue
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index cb72af014..dc35236f2 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -235,8 +235,36 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
}
},
- cancelHandler: { [weak self] in
- self?.handleCancel()
+ cancelHandler: { [weak self] pinWasDisabled in
+ guard let self = self else { return }
+
+ if pinWasDisabled {
+ // PIN was disabled due to max attempts
+ // Try biometric as fallback if available
+ if vaultStore.isBiometricAuthEnabled() {
+ do {
+ // Try to unlock with biometric
+ try vaultStore.unlockVault()
+
+ // Success - process the credential request
+ if let passkeyRequest = self.quickReturnPasskeyRequest {
+ self.handleQuickReturnPasskeyCredential(vaultStore: vaultStore, request: passkeyRequest)
+ } else if let passwordRequest = self.quickReturnPasswordRequest {
+ self.handleQuickReturnPasswordCredential(vaultStore: vaultStore, request: passwordRequest)
+ }
+ } catch {
+ // Biometric failed - cancel
+ print("Biometric fallback failed after PIN lockout: \(error)")
+ self.handleCancel()
+ }
+ } else {
+ // No other auth method - cancel
+ self.handleCancel()
+ }
+ } else {
+ // User manually cancelled
+ self.handleCancel()
+ }
}
)
@@ -525,8 +553,8 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
// Check if PIN is available as fallback
if !pinEnabled {
let alert = UIAlertController(
- title: String(format: NSLocalizedString("biometric_required", comment: ""), authMethod),
- message: String(format: NSLocalizedString("biometric_required_message", comment: ""), authMethod),
+ title: String(format: NSLocalizedString("auth_required", comment: ""), authMethod),
+ message: String(format: NSLocalizedString("auth_required_message", comment: ""), authMethod),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .default) { [weak self] _ in
diff --git a/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift b/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
index 6cf1f7e59..1f307e585 100644
--- a/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
+++ b/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
@@ -100,8 +100,24 @@ class UnlockCoordinator: ObservableObject {
self.onUnlocked()
}
},
- cancelHandler: { [weak self] in
- self?.cancel()
+ cancelHandler: { [weak self] pinWasDisabled in
+ guard let self = self else { return }
+
+ if pinWasDisabled {
+ // PIN was disabled due to max attempts
+ // Try biometric as fallback if available
+ if self.vaultStore.isBiometricAuthEnabled() {
+ Task {
+ await self.attemptBiometricUnlock()
+ }
+ } else {
+ // No other auth method available - cancel
+ self.cancel()
+ }
+ } else {
+ // User manually cancelled - just cancel
+ self.cancel()
+ }
}
)
}
diff --git a/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings b/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings
index b34620702..9eca1401a 100644
Binary files a/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings and b/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings differ
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 6e7851f3d..1d847038c 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -859,10 +859,16 @@ public class VaultManager: NSObject {
}
}
},
- cancelHandler: {
- // User cancelled
+ cancelHandler: { pinWasDisabled in
+ // Dismiss the view
rootVC.dismiss(animated: true) {
- reject("USER_CANCELLED", "User cancelled PIN unlock", nil)
+ if pinWasDisabled {
+ // PIN was disabled due to max attempts
+ reject("PIN_DISABLED", "PIN was disabled after too many failed attempts", nil)
+ } else {
+ // User manually cancelled
+ reject("USER_CANCELLED", "User cancelled PIN unlock", nil)
+ }
}
}
)
diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
index a9edd39cd..673a5e94f 100644
--- a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
+++ b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
@@ -1,4 +1,5 @@
import SwiftUI
+import UIKit
private let locBundle = Bundle.vaultUI
@@ -288,12 +289,12 @@ public class PinUnlockViewModel: ObservableObject {
public let pinLength: Int?
private let unlockHandler: (String) async throws -> Void
- private let cancelHandler: () -> Void
+ private let cancelHandler: (Bool) -> Void // Bool indicates if PIN was disabled/locked
public init(
pinLength: Int?,
unlockHandler: @escaping (String) async throws -> Void,
- cancelHandler: @escaping () -> Void
+ cancelHandler: @escaping (Bool) -> Void
) {
self.pinLength = pinLength
self.unlockHandler = unlockHandler
@@ -328,7 +329,7 @@ public class PinUnlockViewModel: ObservableObject {
}
public func cancel() {
- cancelHandler()
+ cancelHandler(false) // User manually cancelled
}
private func attemptUnlock() async {
@@ -341,18 +342,36 @@ public class PinUnlockViewModel: ObservableObject {
// Success - the handler will navigate away or complete the flow
// Keep loading state active since we're navigating
} catch let nsError as NSError {
- // Handle unlock errors
+ // Check for PIN disabled errors (error code 25)
+ // This occurs when PIN was disabled due to max attempts or configuration issue
+ if nsError.code == 25 {
+ // PIN is no longer available - auto-dismiss the view
+ // This happens when user enters wrong PIN too many times
+ isUnlocking = false
+ cancelHandler(true)
+ return
+ }
+
+ // Handle other unlock errors (incorrect PIN, etc.)
isUnlocking = false
self.error = nsError.localizedDescription
+ triggerErrorFeedback()
shakeAndClear()
} catch let genericError {
// Generic error
isUnlocking = false
self.error = String(localized: "unlock_failed", bundle: locBundle)
+ triggerErrorFeedback()
shakeAndClear()
}
}
+ private func triggerErrorFeedback() {
+ // Trigger haptic feedback for error
+ let generator = UINotificationFeedbackGenerator()
+ generator.notificationOccurred(.error)
+ }
+
private func shakeAndClear() {
// Clear the PIN after a short delay to show error
Task {
diff --git a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings
index 5a0d6c72d..751c85683 100644
Binary files a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings and b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings differ