diff --git a/app/src/main/java/com/mylloon/mobidl/Credentials.kt b/app/src/main/java/com/mylloon/mobidl/Credentials.kt index 692dbde..ab2abca 100644 --- a/app/src/main/java/com/mylloon/mobidl/Credentials.kt +++ b/app/src/main/java/com/mylloon/mobidl/Credentials.kt @@ -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 = + 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() } }