Implemented persisting new password only if changed database password has been successful
This commit is contained in:
parent
e8749385ec
commit
93254c1d21
|
@ -41,12 +41,14 @@ open class RoomBankingPersistence(protected open val applicationContext: Context
|
||||||
return openDatabase(password)
|
return openDatabase(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changePassword(newPassword: String?) {
|
override fun changePassword(newPassword: String?): Boolean {
|
||||||
if (this::database.isInitialized) {
|
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
|
else { // database hasn't been opened yet, that means we're on the first app run
|
||||||
openDatabase(newPassword)
|
return openDatabase(newPassword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,9 @@ open class BankingPersistenceJson(
|
||||||
return true
|
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
|
// TODO: may implement data decryption. But then we have to store newPassword to be able to encrypt data
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,12 +173,13 @@ open class AuthenticationService(
|
||||||
settings.salt = encodeToBase64(salt)
|
settings.salt = encodeToBase64(salt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveAuthenticationSettings(settings)) {
|
if (persistence.changePassword(newPassword)) {
|
||||||
this.authenticationType = type
|
if (saveAuthenticationSettings(settings)) {
|
||||||
this.encryptionCipherForBiometric = null
|
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 true
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -8,7 +8,7 @@ interface IBankingPersistence {
|
||||||
|
|
||||||
fun decryptData(password: String?): Boolean
|
fun decryptData(password: String?): Boolean
|
||||||
|
|
||||||
fun changePassword(newPassword: String?)
|
fun changePassword(newPassword: String?): Boolean
|
||||||
|
|
||||||
|
|
||||||
fun saveOrUpdateBank(bank: TypedBankData, allBanks: List<TypedBankData>)
|
fun saveOrUpdateBank(bank: TypedBankData, allBanks: List<TypedBankData>)
|
||||||
|
|
|
@ -10,8 +10,8 @@ open class NoOpBankingPersistence : IBankingPersistence {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changePassword(newPassword: String?) {
|
override fun changePassword(newPassword: String?): Boolean {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue