Removed unnecessary steps from setPasswords()
This commit is contained in:
parent
3da594b846
commit
08b7eb28a7
|
@ -17,6 +17,7 @@ class AuthenticationService {
|
||||||
static private let Key = ">p(Z5&RRA,@_+W0#" // length = 16 // TODO: find a better way to store key
|
static private let Key = ">p(Z5&RRA,@_+W0#" // length = 16 // TODO: find a better way to store key
|
||||||
|
|
||||||
static private let IV = "drowssapdrowssap" // length = 16
|
static private let IV = "drowssapdrowssap" // length = 16
|
||||||
|
|
||||||
|
|
||||||
private let biometricAuthenticationService = BiometricAuthenticationService()
|
private let biometricAuthenticationService = BiometricAuthenticationService()
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ class AuthenticationService {
|
||||||
if let loginPassword = userLoginPassword {
|
if let loginPassword = userLoginPassword {
|
||||||
databasePassword = concatPasswords(loginPassword, databasePassword)
|
databasePassword = concatPasswords(loginPassword, databasePassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
return persistence.decryptData(password: map(databasePassword))
|
return persistence.decryptData(password: map(databasePassword))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
|
var databasePassword = ""
|
||||||
let currentPassword = try? passwordItem.readPassword()
|
|
||||||
|
if let newDefaultPassword = createAndSetDefaultPassword(useBiometricAuthentication) {
|
||||||
try? passwordItem.deleteItem()
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue