fix: crash on incorrect password

This commit is contained in:
rebelonion 2024-02-06 01:53:49 -06:00
parent 0c6fad91ca
commit 8d7b86a667
4 changed files with 40 additions and 14 deletions

View file

@ -53,22 +53,28 @@ class LoginFragment : Fragment() {
if (password != null) {
val salt = jsonString.copyOfRange(0, 16)
val encrypted = jsonString.copyOfRange(16, jsonString.size)
val decryptedJson = PreferenceKeystore.decryptWithPassword(
password,
encrypted,
salt
)
val decryptedJson = try {
PreferenceKeystore.decryptWithPassword(
password,
encrypted,
salt
)
} catch (e: Exception) {
toast("Incorrect password")
return@passwordAlertDialog
}
if(PreferencePackager.unpack(decryptedJson))
println("Settings imported")
restartApp()
} else {
toast("Password cannot be empty")
}
}
} else {
} else if (name.endsWith(".ani")) {
val decryptedJson = jsonString.toString(Charsets.UTF_8)
if(PreferencePackager.unpack(decryptedJson))
restartApp()
} else {
toast("Invalid file type")
}
} catch (e: Exception) {
e.printStackTrace()