🔐 Add SID

This commit is contained in:
Mylloon 2021-08-30 14:04:09 +02:00
parent aef919f05b
commit d6f936e4e8

View file

@ -104,6 +104,36 @@ class Credentials {
} else null } else null
} }
fun storeSID(sid: String) {
val sidEncrypted = encrypt(sid) // encrypt sid
val context = MainActivity.applicationContext() // get app context
// write encrypted data to the app preference
val sharedPref = context.getSharedPreferences(sharedPref, MODE_PRIVATE)
with(sharedPref?.edit()) {
this?.putString("sid", sidEncrypted.contentToString())
this?.apply()
}
}
fun getSID(): String? {
val context = MainActivity.applicationContext() // get app context
// read encrypted data from the app preference
val sharedPref = context.getSharedPreferences(sharedPref, MODE_PRIVATE)
val data: String? = sharedPref.getString("sid", null)
return if (data != null) {
val split: List<String> =
data.substring(1, data.length - 1).split(", ")
val array = ByteArray(split.size)
for (i in split.indices) {
array[i] = split[i].toByte()
}
decrypt(array)
} else null
}
fun delete() { fun delete() {
val context = MainActivity.applicationContext() // get app context val context = MainActivity.applicationContext() // get app context
@ -112,6 +142,7 @@ class Credentials {
with(sharedPref.edit()) { with(sharedPref.edit()) {
this.remove("username") this.remove("username")
this.remove("password") this.remove("password")
this.remove("sid")
this.apply() this.apply()
} }
} }