diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetMainCredentialDialogFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetMainCredentialDialogFragment.kt index 9a28fd940..0efb572c7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetMainCredentialDialogFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetMainCredentialDialogFragment.kt @@ -159,9 +159,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() { keyFileSelectionView.error = null keyFileCheckBox.isChecked = true keyFileSelectionView.uri = pathUri - if (lengthFile <= 0L) { - showEmptyKeyFileConfirmationDialog() - } + showLengthKeyFileConfirmationDialog(lengthFile) } } } @@ -339,21 +337,31 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() { } } - private fun showEmptyKeyFileConfirmationDialog() { + private fun showLengthKeyFileConfirmationDialog(length: Long) { activity?.let { val builder = AlertDialog.Builder(it) builder.setMessage(SpannableStringBuilder().apply { - append(getString(R.string.warning_empty_keyfile)) - append("\n\n") append(getString(R.string.warning_empty_keyfile_explanation)) - append("\n\n") - append(getString(R.string.warning_sure_add_file)) - }) - .setPositiveButton(android.R.string.ok) { _, _ -> } - .setNegativeButton(android.R.string.cancel) { _, _ -> - keyFileCheckBox.isChecked = false - keyFileSelectionView.uri = null - } + var warning = false + if (length <= 0L) { + warning = true + append("\n\n") + append(getString(R.string.warning_empty_keyfile)) + } else if (length > 10485760L) { + warning = true + append("\n\n") + append(getString(R.string.warning_large_keyfile)) + } + if (warning) { + append("\n\n") + append(getString(R.string.warning_sure_add_file)) + } + }) + .setPositiveButton(android.R.string.ok) { _, _ -> } + .setNegativeButton(android.R.string.cancel) { _, _ -> + keyFileCheckBox.isChecked = false + keyFileSelectionView.uri = null + } mEmptyKeyFileConfirmationDialog = builder.create() mEmptyKeyFileConfirmationDialog?.show() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 73da0df2a..ce7563d7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -373,6 +373,7 @@ Removing unlinked data may decrease the size of your database but may also delete data used for KeePass plugins. Remove this data anyway? It is not recommended to add an empty keyfile. + It is not recommended to add a large keyfile, this may prevent the database from opening. The content of the keyfile should never be changed, and in the best case, should contain randomly generated data. The information contained in your database file has been modified outside the app. Merge the data, overwrite the external modifications by saving the database or reload it with the latest changes.