From d6f936e4e8c5aaf17e78e5d404df9a94e63ea036 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 30 Aug 2021 14:04:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=90=20Add=20SID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mylloon/mobidl/Credentials.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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() } }