Removed unnecessary steps from setPasswords()

This commit is contained in:
dankito 2020-10-16 15:49:24 +02:00
parent 3da594b846
commit 08b7eb28a7
1 changed files with 15 additions and 29 deletions

View File

@ -18,6 +18,7 @@ class AuthenticationService {
static private let IV = "drowssapdrowssap" // length = 16 static private let IV = "drowssapdrowssap" // length = 16
private let biometricAuthenticationService = BiometricAuthenticationService() private let biometricAuthenticationService = BiometricAuthenticationService()
private let persistence: IBankingPersistence private let persistence: IBankingPersistence
@ -210,39 +211,24 @@ class AuthenticationService {
@discardableResult @discardableResult
private func setPasswords(_ useBiometricAuthentication: Bool, _ newLoginPassword: String?) -> Bool { private func setPasswords(_ useBiometricAuthentication: Bool, _ newLoginPassword: String?) -> Bool {
do { deleteDefaultPassword(useBiometricAuthentication) // TODO: needed?
let passwordItem = createDefaultPasswordKeychainItem(useBiometricAuthentication)
let currentPassword = try? passwordItem.readPassword() var databasePassword = ""
try? passwordItem.deleteItem() if let newDefaultPassword = createAndSetDefaultPassword(useBiometricAuthentication) {
databasePassword = newDefaultPassword
var databasePassword = currentPassword ?? ""
if let currentPassword = currentPassword, let encryped = encrypt(currentPassword) {
try passwordItem.savePassword(encryped)
}
else {
if let newDefaultPassword = createNewDefaultPassword(useBiometricAuthentication) {
databasePassword = newDefaultPassword
}
}
if let newLoginPassword = newLoginPassword {
setLoginPassword(newLoginPassword)
databasePassword = concatPasswords(newLoginPassword, databasePassword)
}
return persistence.changePassword(newPassword: map(databasePassword))
} catch {
NSLog("Could not save default password: \(error)")
} }
return false if let newLoginPassword = newLoginPassword {
setLoginPassword(newLoginPassword)
databasePassword = concatPasswords(newLoginPassword, databasePassword)
}
return persistence.changePassword(newPassword: map(databasePassword))
} }
@discardableResult @discardableResult
private func createNewDefaultPassword(_ useBiometricAuthentication: Bool) -> String? { private func createAndSetDefaultPassword(_ useBiometricAuthentication: Bool) -> String? {
do { do {
let newDefaultPassword = generateRandomPassword(30) let newDefaultPassword = generateRandomPassword(30)