diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/activities/LoginActivity.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/activities/LoginActivity.kt index 2f689197..a7006269 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/activities/LoginActivity.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/activities/LoginActivity.kt @@ -50,7 +50,7 @@ open class LoginActivity : BaseActivity() { lytPasswordAuthentication.visibility = View.GONE btnBiometricAuthentication.customButtonClickHandler = { - authenticationService.authenticateUserWithBiometric { result -> + authenticationService.loginUserWithBiometric { result -> if (result) { btnStartBiometricAuthentication.isEnabled = false @@ -67,7 +67,7 @@ open class LoginActivity : BaseActivity() { protected open fun checkEnteredPasswordAndLogIn() { btnLogin.isEnabled = false - if (authenticationService.authenticateUserWithPassword(edtxtLoginPassword.chars)) { + if (authenticationService.loginUserWithPassword(edtxtLoginPassword.chars)) { navigateToMainActivity() } else { diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/authentication/AuthenticationService.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/authentication/AuthenticationService.kt index f62ddbe4..60ff7974 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/authentication/AuthenticationService.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/authentication/AuthenticationService.kt @@ -55,7 +55,7 @@ open class AuthenticationService( } - open fun authenticateUserWithPassword(enteredPassword: CharArray): Boolean { + open fun loginUserWithPassword(enteredPassword: CharArray): Boolean { if (isCorrectUserPassword(enteredPassword)) { loadAuthenticationSettings()?.let { settings -> return openDatabase(settings, enteredPassword) @@ -92,7 +92,7 @@ open class AuthenticationService( } } - open fun authenticateUserWithBiometric(result: (Boolean) -> Unit) { + open fun loginUserWithBiometric(result: (Boolean) -> Unit) { // Biometric authentication is only supported on Android 6 and above if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) { result(false) diff --git a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift index c9dfe51b..7991acf8 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift +++ b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift @@ -90,21 +90,7 @@ class AuthenticationService { } - // TODO: big bug, in this way it's not possible to set a new password with biometrics - func authenticateUserWithBiometric(_ prompt: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { - biometricAuthenticationService.authenticate(prompt) { successful, error in - var decryptDatabaseResult = false - if successful { - decryptDatabaseResult = self.openDatabase(true, nil) - } - - authenticationResult(successful && decryptDatabaseResult, error) - } - } - - // TODO: implement authenticateUserWithBiometricToSetAsNewAuthenticationMethod() - - func authenticateUserWithPassword(_ enteredPassword: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { + func loginUserWithPassword(_ enteredPassword: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { if let storedHash = readLoginPasswordHash() { if let salt = readLoginPasswordSalt() { if let hashOfEnteredPassword = hashLoginPassword(enteredPassword, salt) { @@ -121,6 +107,27 @@ class AuthenticationService { authenticationResult(false, "Incorrect password entered".localize()) } + func loginUserWithBiometric(_ prompt: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { + authenticateUserWithBiometric(prompt) { successful, error in + var decryptDatabaseResult = false + if successful { + decryptDatabaseResult = self.openDatabase(true, nil) + } + + authenticationResult(successful && decryptDatabaseResult, error) + } + } + + func authenticateUserWithBiometricToSetAsNewAuthenticationMethod(_ prompt: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { + authenticateUserWithBiometric(prompt, authenticationResult) + } + + private func authenticateUserWithBiometric(_ prompt: String, _ authenticationResult: @escaping (Bool, String?) -> Void) { + biometricAuthenticationService.authenticate(prompt) { successful, error in + authenticationResult(successful, error) + } + } + @discardableResult private func openDatabase(_ useBiometricAuthentication: Bool, _ userLoginPassword: String?) -> Bool { if var databasePassword = readDefaultPassword(useBiometricAuthentication) { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift index f4777f9c..db8d0fc5 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift @@ -94,7 +94,7 @@ struct LoginDialog: View { private func loginWithBiometricAuthentication() { - authenticationService.authenticateUserWithBiometric("Authenticate with biometrics to unlock app reason", self.handleAuthenticationResult) + authenticationService.loginUserWithBiometric("Authenticate with biometrics to unlock app reason", self.handleAuthenticationResult) } private func loginWithPasswordOnReturnKeyPress() -> Bool { @@ -104,7 +104,7 @@ struct LoginDialog: View { } private func loginWithPassword() { - authenticationService.authenticateUserWithPassword(enteredPassword, self.handleAuthenticationResult) + authenticationService.loginUserWithPassword(enteredPassword, self.handleAuthenticationResult) } private func handleAuthenticationResult(success: Bool, errorMessage: String?) { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift index c829ec7a..16a47cad 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift @@ -184,7 +184,7 @@ struct ProtectAppSettingsDialog: View { } private func doBiometricAuthentication() { - authenticationService.authenticateUserWithBiometric("Authenticate to encrypt data with %@".localize(supportedBiometricAuthenticationLocalizedName)) { success, errorMessage in + authenticationService.authenticateUserWithBiometricToSetAsNewAuthenticationMethod("Authenticate to encrypt data with %@".localize(supportedBiometricAuthenticationLocalizedName)) { success, errorMessage in self.successfullyAuthenticatedWithBiometricAuthentication = success } }