Implemented persisting new password only if changed database password has been successful

This commit is contained in:
dankito 2020-10-13 17:08:54 +02:00
parent e8749385ec
commit 93254c1d21
5 changed files with 16 additions and 12 deletions

View File

@ -41,12 +41,14 @@ open class RoomBankingPersistence(protected open val applicationContext: Context
return openDatabase(password)
}
override fun changePassword(newPassword: String?) {
override fun changePassword(newPassword: String?): Boolean {
if (this::database.isInitialized) {
database.query("PRAGMA rekey = '$newPassword';", emptyArray())
val cursor = database.query("PRAGMA rekey = '$newPassword';", emptyArray())
return cursor.count == 1 // TODO: also check if first column content is 'ok' ?
}
else { // database hasn't been opened yet, that means we're on the first app run
openDatabase(newPassword)
return openDatabase(newPassword)
}
}

View File

@ -40,8 +40,9 @@ open class BankingPersistenceJson(
return true
}
override fun changePassword(newPassword: String?) {
override fun changePassword(newPassword: String?): Boolean {
// TODO: may implement data decryption. But then we have to store newPassword to be able to encrypt data
return true
}

View File

@ -173,13 +173,14 @@ open class AuthenticationService(
settings.salt = encodeToBase64(salt)
}
if (persistence.changePassword(newPassword)) {
if (saveAuthenticationSettings(settings)) {
this.authenticationType = type
this.encryptionCipherForBiometric = null
persistence.changePassword(newPassword) // TODO: actually this is bad. If changing password fails then password is saved in AuthenticationSettings but DB has a different password
return true
}
}
return false
}

View File

@ -8,7 +8,7 @@ interface IBankingPersistence {
fun decryptData(password: String?): Boolean
fun changePassword(newPassword: String?)
fun changePassword(newPassword: String?): Boolean
fun saveOrUpdateBank(bank: TypedBankData, allBanks: List<TypedBankData>)

View File

@ -10,8 +10,8 @@ open class NoOpBankingPersistence : IBankingPersistence {
return true
}
override fun changePassword(newPassword: String?) {
override fun changePassword(newPassword: String?): Boolean {
return true
}