Removed unnecessary steps from setPasswords()
This commit is contained in:
parent
3da594b846
commit
08b7eb28a7
|
@ -18,6 +18,7 @@ class AuthenticationService {
|
|||
|
||||
static private let IV = "drowssapdrowssap" // length = 16
|
||||
|
||||
|
||||
private let biometricAuthenticationService = BiometricAuthenticationService()
|
||||
|
||||
private let persistence: IBankingPersistence
|
||||
|
@ -210,23 +211,13 @@ class AuthenticationService {
|
|||
|
||||
@discardableResult
|
||||
private func setPasswords(_ useBiometricAuthentication: Bool, _ newLoginPassword: String?) -> Bool {
|
||||
do {
|
||||
let passwordItem = createDefaultPasswordKeychainItem(useBiometricAuthentication)
|
||||
deleteDefaultPassword(useBiometricAuthentication) // TODO: needed?
|
||||
|
||||
let currentPassword = try? passwordItem.readPassword()
|
||||
var databasePassword = ""
|
||||
|
||||
try? passwordItem.deleteItem()
|
||||
|
||||
var databasePassword = currentPassword ?? ""
|
||||
|
||||
if let currentPassword = currentPassword, let encryped = encrypt(currentPassword) {
|
||||
try passwordItem.savePassword(encryped)
|
||||
}
|
||||
else {
|
||||
if let newDefaultPassword = createNewDefaultPassword(useBiometricAuthentication) {
|
||||
if let newDefaultPassword = createAndSetDefaultPassword(useBiometricAuthentication) {
|
||||
databasePassword = newDefaultPassword
|
||||
}
|
||||
}
|
||||
|
||||
if let newLoginPassword = newLoginPassword {
|
||||
setLoginPassword(newLoginPassword)
|
||||
|
@ -234,15 +225,10 @@ class AuthenticationService {
|
|||
}
|
||||
|
||||
return persistence.changePassword(newPassword: map(databasePassword))
|
||||
} catch {
|
||||
NSLog("Could not save default password: \(error)")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func createNewDefaultPassword(_ useBiometricAuthentication: Bool) -> String? {
|
||||
private func createAndSetDefaultPassword(_ useBiometricAuthentication: Bool) -> String? {
|
||||
do {
|
||||
let newDefaultPassword = generateRandomPassword(30)
|
||||
|
||||
|
|
Loading…
Reference in New Issue