Allow empty backup/restore password

This commit is contained in:
Juha Heinanen
2026-07-07 13:54:18 +03:00
parent 60cfe024f5
commit 0e3e587991
3 changed files with 18 additions and 20 deletions
@@ -508,6 +508,7 @@ object CustomElements {
ctx: Context, ctx: Context,
showPasswordDialog: MutableState<Boolean>, showPasswordDialog: MutableState<Boolean>,
password: MutableState<String>, password: MutableState<String>,
emptyOk: Boolean = false,
keyboardController: SoftwareKeyboardController?, keyboardController: SoftwareKeyboardController?,
title: String, title: String,
message: String = "", message: String = "",
@@ -614,7 +615,7 @@ object CustomElements {
keyboardController?.hide() keyboardController?.hide()
showPasswordDialog.value = false showPasswordDialog.value = false
password.value = password.value.trim() password.value = password.value.trim()
if (!Account.checkAuthPass(password.value)) { if (!(emptyOk && password.value.isEmpty()) && !Account.checkAuthPass(password.value)) {
Toast.makeText( Toast.makeText(
ctx, ctx,
String.format( String.format(
@@ -410,16 +410,15 @@ private fun MainScreen(
ctx = ctx, ctx = ctx,
showPasswordDialog = showPasswordDialog, showPasswordDialog = showPasswordDialog,
password = password, password = password,
emptyOk = true,
keyboardController = keyboardController, keyboardController = keyboardController,
title = passwordTitle.value, title = passwordTitle.value,
okAction = { okAction = {
if (password.value != "") {
if (passwordTitle.value == encryptPasswordTitle) if (passwordTitle.value == encryptPasswordTitle)
backup(ctx, password.value) backup(ctx, password.value)
else else
restore(ctx, password.value, onRestartClick) restore(ctx, password.value, onRestartClick)
password.value = "" password.value = ""
}
}, },
cancelAction = { cancelAction = {
if (downloadsOutputUri != null) { if (downloadsOutputUri != null) {
@@ -100,10 +100,9 @@ object Utils {
fun getNameValue(string: String, name: String): ArrayList<String> { fun getNameValue(string: String, name: String): ArrayList<String> {
val lines = string.split("\n") val lines = string.split("\n")
val result = ArrayList<String>() val result = ArrayList<String>()
for (line in lines) { for (line in lines)
if (line.startsWith(name)) if (line.startsWith(name))
result.add((line.substring(name.length).trim()).split(" \t")[0]) result.add((line.substring(name.length).trim()).split(" \t")[0])
}
return result return result
} }
@@ -178,8 +177,7 @@ object Utils {
ctx.getString(R.string.anonymous) ctx.getString(R.string.anonymous)
else if (host == "unknown.invalid") else if (host == "unknown.invalid")
ctx.getString(R.string.unknown) ctx.getString(R.string.unknown)
else else if (params.isEmpty())
if (params.isEmpty())
"$user@$host" "$user@$host"
else else
"$user@$host;" + params.joinToString(";") "$user@$host;" + params.joinToString(";")
@@ -750,7 +748,7 @@ object Utils {
} }
fun encryptToUri(ctx: Context, uri: Uri, content: ByteArray, password: String): Boolean { fun encryptToUri(ctx: Context, uri: Uri, content: ByteArray, password: String): Boolean {
val obj = encrypt(content, password.toCharArray()) val obj = if (password == "") content else encrypt(content, password.toCharArray())
try { try {
val stream = ctx.contentResolver.openOutputStream(uri) val stream = ctx.contentResolver.openOutputStream(uri)
if (stream != null) if (stream != null)
@@ -781,7 +779,7 @@ object Utils {
try { try {
ObjectInputStream(stream).use { ObjectInputStream(stream).use {
val content = it.readObject() as ByteArray val content = it.readObject() as ByteArray
plainData = decrypt(content, password.toCharArray()) plainData = if (password == "") content else decrypt(content, password.toCharArray())
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.w(TAG, "decryptFromUri as ByteArray failed: $e") Log.w(TAG, "decryptFromUri as ByteArray failed: $e")