🔐 Add SID
This commit is contained in:
parent
aef919f05b
commit
d6f936e4e8
1 changed files with 31 additions and 0 deletions
|
@ -104,6 +104,36 @@ class Credentials {
|
|||
} 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() {
|
||||
val context = MainActivity.applicationContext() // get app context
|
||||
|
||||
|
@ -112,6 +142,7 @@ class Credentials {
|
|||
with(sharedPref.edit()) {
|
||||
this.remove("username")
|
||||
this.remove("password")
|
||||
this.remove("sid")
|
||||
this.apply()
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue