feat: add password reveal toggle, friendlier KDBX4 wrong-password message
Adds an eye-icon toggle to the master password field (UnlockView) so users can verify what they typed before submitting. Also maps KDBX4's ERROR_HEADER_HASH_VERIFICATION_FAILED -- surfaced via the header HMAC check, which is password-derived -- to KDBXError.invalidPassword alongside the existing passwordAndOrKeyfileWrong check. KeePassKit uses this same error code for both a wrong password/keyfile and genuine file corruption (it doesn't distinguish the two), so the message hedges: "Incorrect password, or this vault file is corrupted." Found while testing against a real KDBX4 vault, which was surfacing this as a raw, unreadable NSError string before the previous commit's LocalizedError fix, and as *no* friendly message at all before this one (the error code wasn't in the recognized set yet). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -18,7 +18,15 @@ public struct KDBXDocument {
|
||||
let tree = try KPKTree(contentsOf: url, key: key)
|
||||
return KDBXMapper.database(from: tree)
|
||||
} catch let err as NSError {
|
||||
if err.domain == KPKErrorDomain && err.code == KPKErrorCode.passwordAndOrKeyfileWrong.rawValue {
|
||||
let wrongKeyCodes: Set<Int> = [
|
||||
Int(KPKErrorCode.passwordAndOrKeyfileWrong.rawValue),
|
||||
// KDBX4's header HMAC check (which is password-derived) uses this same
|
||||
// error code for both a wrong password/keyfile and true file corruption --
|
||||
// KeePassKit doesn't distinguish the two. Wrong password is by far the
|
||||
// more common cause, so we surface it as such.
|
||||
Int(KPKErrorCode.kdbxHeaderHashVerificationFailed.rawValue),
|
||||
]
|
||||
if err.domain == KPKErrorDomain && wrongKeyCodes.contains(err.code) {
|
||||
throw KDBXError.invalidPassword
|
||||
}
|
||||
throw KDBXError.parseError(err.localizedDescription)
|
||||
|
||||
@@ -11,7 +11,7 @@ extension KDBXError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidPassword:
|
||||
return "Incorrect password."
|
||||
return "Incorrect password, or this vault file is corrupted."
|
||||
case .fileNotFound:
|
||||
return "The vault file could not be found."
|
||||
case .parseError(let message):
|
||||
|
||||
Reference in New Issue
Block a user