Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Security/ChangePasswordSheet.swift8// Module : Security9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import QyvoraVault43import QyvoraWallet44import QyvoraUI4546/// Changes the master password of the vault. The current password is the authentication; the strength of the new one47/// is measured by the vault's estimator and recorded for the Quantum Shield.48struct ChangePasswordSheet: View {49 @Environment(WalletStore.self) private var store50 @Environment(\.dismiss) private var dismiss51 @State private var current = ""52 @State private var new = ""53 @State private var confirmation = ""54 @State private var error: String?55 @State private var busy = false56 @State private var done = false5758 var estimate: PasswordQuality.Estimate? { new.isEmpty ? nil : store.service?.passwordQuality(new) }59 var mismatch: Bool { !confirmation.isEmpty && confirmation != new }60 var canSubmit: Bool { !current.isEmpty && !new.isEmpty && new == confirmation && new != current }6162 var body: some View {63 ScrollView {64 VStack(alignment: .leading, spacing: 18) {65 SheetHeader("Change master password", subtitle: "The new password re-wraps the same master key. PIN and biometric unlock are not affected.") { dismiss() }66 if done {67 WarningBanner(.positive, title: "Password changed", message: "The vault now opens with the new password. Encrypted backups made earlier keep their own password.")68 Button("Done") { dismiss() }.buttonStyle(.qPrimary)69 } else {70 PasswordField("Current password", text: $current)71 PasswordField("New password", text: $new, strength: estimate.map(PasswordStrength.init), isNewPassword: true)72 PasswordField("Repeat the new password", text: $confirmation, isNewPassword: true) { submit() }73 if mismatch {74 Label("The two entries differ.", systemImage: QTone.warning.systemImage).font(QFont.caption).foregroundStyle(QColor.warning)75 }76 if !new.isEmpty, new == current {77 Label("The new password is the same as the current one.", systemImage: QTone.warning.systemImage).font(QFont.caption).foregroundStyle(QColor.warning)78 }79 if !new.isEmpty, let reason = WalletService.passwordRejection(new) {80 WarningBanner(.warning, title: "Password not accepted",81 message: reason + " A copy of the vault file must resist an offline guessing attack.")82 }83 SecInlineError(error)84 LoadingButton("Change password", loadingTitle: "Deriving the keys", systemImage: "key", state: busy ? .loading : .idle) { submit() }85 .disabled(!canSubmit)86 Explanation("There is no password reset. If the password is lost, the wallet is restored from the recovery phrase.")87 }88 }89 .padding(20)90 .frame(maxWidth: 560, alignment: .leading)91 .frame(maxWidth: .infinity)92 }93 .scrollDismissesKeyboard(.interactively)94 .qScreen()95 .privacySensitive()96 .interactiveDismissDisabled(busy)97 .sensoryFeedback(.success, trigger: done)98 .onDisappear { clear() }99 }100101 func clear() {102 current = ""103 new = ""104 confirmation = ""105 }106107 func submit() {108 guard canSubmit, !busy else { return }109 busy = true110 error = nil111 let old = current, fresh = new112 Task {113 do {114 try await store.run { try await $0.changePassword(current: old, new: fresh) }115 clear()116 done = true117 } catch {118 self.error = SecurityError.text(error)119 }120 busy = false121 }122 }123}124