From 722d2fcd71a61c54252db1e59c6e7602819e61e3 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Tue, 17 Sep 2024 20:38:03 +0530 Subject: [PATCH] Fix csv mal function exception (#974) * Disable biometric login after 24 hours of last password login Fixes #951 Add logic to disable biometric login if the user has not logged in via password in the last 24 hours. * **UserSettings.kt** - Add `lastPasswordLoginTime` attribute to track the last password login time. * **BiometricPrompt.kt** - Add logic to check `lastPasswordLoginTime` and disable biometric login if the last password login was more than 24 hours ago. - Add function `updateLastBiometricLoginTime` to update the last biometric login time. * **AuthScreen.kt** - Add logic to reset `lastPasswordLoginTime` when users log in via password. * **SharedPreferenceUtils.kt** - Add functions `updateLastBiometricLoginTime` and `updateLastPasswordLoginTime` to update the respective times in `UserSettings`. * **ButtonBar.kt** - Add logic to reset `lastPasswordLoginTime` when users log in via password. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/yogeshpaliyal/KeyPass/issues/951?shareId=XXXX-XXXX-XXXX-XXXX). * feat: fix changes * feat: cleanup * fix: CSV MalFunction Crash --- .../importer/KeePassAccountImporter.kt | 47 ++++++++++--------- app/src/main/res/values/strings.xml | 2 + 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/importer/KeePassAccountImporter.kt b/app/src/main/java/com/yogeshpaliyal/keypass/importer/KeePassAccountImporter.kt index d2fc5568..02ab9190 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/importer/KeePassAccountImporter.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/importer/KeePassAccountImporter.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.platform.LocalContext import com.opencsv.CSVReader +import com.opencsv.exceptions.CsvMalformedLineException import com.yogeshpaliyal.common.data.AccountModel import com.yogeshpaliyal.keypass.R import com.yogeshpaliyal.keypass.ui.redux.actions.Action @@ -23,29 +24,33 @@ class KeePassAccountImporter : AccountsImporter { val context = LocalContext.current LaunchedEffect(key1 = file, block = { - val inputStream = context.contentResolver.openInputStream(file) - val reader = CSVReader(inputStream?.reader()) - val myEntries: List> = reader.readAll() - val headers = myEntries[0] - val result = myEntries.drop(1).map { data -> - headers.zip(data).toMap() - } - val listOfAccounts = ArrayList() - result.forEach { - listOfAccounts.add( - AccountModel( - title = it["Title"], - notes = it["Notes"], - password = it["Password"], - username = it["Username"], - site = it["URL"], - tags = it["Group"], - secret = if (it["TOTP"].isNullOrBlank()) null else it["TOTP"] + try { + val inputStream = context.contentResolver.openInputStream(file) + val reader = CSVReader(inputStream?.reader()) + val myEntries: List> = reader.readAll() + val headers = myEntries[0] + val result = myEntries.drop(1).map { data -> + headers.zip(data).toMap() + } + val listOfAccounts = ArrayList() + result.forEach { + listOfAccounts.add( + AccountModel( + title = it["Title"], + notes = it["Notes"], + password = it["Password"], + username = it["Username"], + site = it["URL"], + tags = it["Group"], + secret = if (it["TOTP"].isNullOrBlank()) null else it["TOTP"] + ) ) - ) + } + resolve(listOfAccounts) + onCompleteOrCancel(ToastAction(R.string.backup_restored)) + } catch (e: CsvMalformedLineException) { + onCompleteOrCancel(ToastAction(R.string.invalid_csv)) } - resolve(listOfAccounts) - onCompleteOrCancel(ToastAction(R.string.backup_restored)) }) LoadingDialog() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2271b3d6..e88eff96 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,8 @@ Generate Password Backup Restored + Invalid CSV file + Invalid Keyphrase Backup Completed