fix: Add warning for KeyFile length #1780

This commit is contained in:
J-Jamet
2024-09-06 15:55:36 +02:00
parent 800badd2a4
commit ffcfe966d2
2 changed files with 23 additions and 14 deletions

View File

@@ -159,9 +159,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
keyFileSelectionView.error = null
keyFileCheckBox.isChecked = true
keyFileSelectionView.uri = pathUri
if (lengthFile <= 0L) {
showEmptyKeyFileConfirmationDialog()
}
showLengthKeyFileConfirmationDialog(lengthFile)
}
}
}
@@ -339,15 +337,25 @@ 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))
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) { _, _ ->

View File

@@ -373,6 +373,7 @@
<string name="warning_remove_unlinked_attachment">Removing unlinked data may decrease the size of your database but may also delete data used for KeePass plugins.</string>
<string name="warning_sure_remove_data">Remove this data anyway?</string>
<string name="warning_empty_keyfile">It is not recommended to add an empty keyfile.</string>
<string name="warning_large_keyfile">It is not recommended to add a large keyfile, this may prevent the database from opening.</string>
<string name="warning_empty_keyfile_explanation">The content of the keyfile should never be changed, and in the best case, should contain randomly generated data.</string>
<string name="warning_database_info_changed">The information contained in your database file has been modified outside the app.</string>
<string name="warning_database_info_changed_options">Merge the data, overwrite the external modifications by saving the database or reload it with the latest changes.</string>