From 97d9e8bcfb71caa1a6c4d3541e0d539bf949d5e0 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Mon, 18 Feb 2019 14:13:02 -0600 Subject: [PATCH] Make sure to save the hash of the user selected PIN plus the salt used to generate it are both saved into the shared preferences, when creating or importing an account. --- .../fragments/BaseAccountFragment.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt index 9864007..e1cf1bb 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt @@ -32,13 +32,14 @@ abstract class BaseAccountFragment : ConnectedFragment() { * @param accountProperties Account properties object */ protected fun onAccountSelected(accountProperties: AccountProperties, pin: String) { - val encryptedPIN = CryptoUtils.encrypt(context!!, pin).trim() + val salt = CryptoUtils.generateSalt() + val hashedPIN = CryptoUtils.createSHA256Hash(salt + pin) - // Stores the user selected PIN encrypted - PreferenceManager.getDefaultSharedPreferences(context!!) - .edit() - .putString(Constants.KEY_HASHED_PIN_PATTERN, encryptedPIN) - .apply() + // Stores the user selected PIN, hashed + PreferenceManager.getDefaultSharedPreferences(context!!).edit() + .putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPIN) + .putString(Constants.KEY_PIN_PATTERN_SALT, salt) + .putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1).apply() // 1 -> PIN // Stores the accounts this key refers to val id = accountProperties.id