Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hint functionality for user password #18

Merged
merged 43 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d522965
Added hint textfield
Bhawna-Ad Jun 23, 2021
7b87626
Added hint textfield
Bhawna-Ad Jun 23, 2021
e91deed
Merge branch 'master' of https://github.com/Ni3verma/Safe-Box into fe…
Bhawna-Ad Jun 23, 2021
51f00dd
Changed the Id according to naming convention
Bhawna-Ad Jun 24, 2021
4d77605
Merge branch 'master' of https://github.com/Ni3verma/Safe-Box into fe…
Bhawna-Ad Jun 24, 2021
88ae7f7
Branch updated
Bhawna-Ad Jun 24, 2021
f27f000
Reverted the accidental changes
Bhawna-Ad Jun 24, 2021
973ef13
Reverted the change
Bhawna-Ad Jun 25, 2021
b4e536f
Added functionality to display and hide the hint inside login fragment.
Bhawna-Ad Jun 26, 2021
ede29b7
Added functionality to display and hide the hint inside login fragment.
Bhawna-Ad Jun 26, 2021
f83ab0d
Added functionality to display and hide the hint inside login fragment.
Bhawna-Ad Jun 26, 2021
3012fab
Updated functionality to show and hide hint in Login Fragment with Ut…
Bhawna-Ad Jun 27, 2021
f0bce71
Merge branch 'feature/add-hint' of https://github.com/Bhawna-Ad/Safe-…
Bhawna-Ad Jun 27, 2021
a350626
Updated Java Version to match build.gradle
Bhawna-Ad Jun 27, 2021
596a4f5
syncing with master branch
Bhawna-Ad Jun 27, 2021
f4d5277
made a few changes
Bhawna-Ad Jun 27, 2021
a8dcbfc
Merge branch 'master' into feature/add-hint
Bhawna-Ad Jun 27, 2021
ae75eda
Updated Util methods
Bhawna-Ad Jun 28, 2021
9802434
Updated the code for displaying hint
Bhawna-Ad Jun 28, 2021
7447faf
Added Encryption function to encrypt hint inside UserDetailDaoSecure
Bhawna-Ad Jul 2, 2021
6f0c71c
Added encryption to hint
Bhawna-Ad Jul 2, 2021
fc24963
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 3, 2021
281cbb6
Added function to call hint in UserDetailsDao
Bhawna-Ad Jul 3, 2021
a129150
Added getHint function in UserDetailsDaoSecure
Bhawna-Ad Jul 3, 2021
9c7269d
Updated the code to get hint
Bhawna-Ad Jul 4, 2021
79de62b
Added method to call dao in repository
Bhawna-Ad Jul 4, 2021
c2a0211
Calling repo method in viewmodel
Bhawna-Ad Jul 6, 2021
bcdd5e4
Added functionality to display hint in login fragment
Bhawna-Ad Jul 6, 2021
b4db97b
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 6, 2021
b02a3e9
Made the required changes
Bhawna-Ad Jul 6, 2021
2e40572
Updated the code
Bhawna-Ad Jul 6, 2021
4141235
Display hint in login screen
Bhawna-Ad Jul 7, 2021
c56e996
Updated the code
Bhawna-Ad Jul 7, 2021
00837ac
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 9, 2021
93f5530
Added validation rule for hint length
Bhawna-Ad Jul 11, 2021
6e0244e
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 11, 2021
aea0f3b
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 11, 2021
582c9f9
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 17, 2021
2efc33b
Merge branch 'master' of https://github.com/Bhawna-Ad/Safe-Box into f…
Bhawna-Ad Jul 18, 2021
62bd890
Added validation check for hint
Bhawna-Ad Jul 18, 2021
a5b95a5
Fixed issues with hint error
Bhawna-Ad Jul 19, 2021
ab901fe
handling hint validation
Ni3verma Jul 24, 2021
7620792
doing validation in background
Ni3verma Jul 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ interface UserDetailsDao {

@Query("select * from user_details limit 1")
suspend fun getUserDetails(): UserDetailsEntity

@Query("select hint from user_details")
suspend fun getHint(): String
Ni3verma marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class UserDetailsEntity(
@PrimaryKey(autoGenerate = true)
val key: Int,
val password: String,
val hint: String,
val hint: String?,
val creationDate: Date,
val updateDate: Date
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ package com.andryoga.safebox.data.db.secureDao
import com.andryoga.safebox.data.db.dao.UserDetailsDao
import com.andryoga.safebox.data.db.entity.UserDetailsEntity
import com.andryoga.safebox.security.interfaces.HashingUtils
import com.andryoga.safebox.security.interfaces.SymmetricKeyUtils
import javax.inject.Inject

class UserDetailsDaoSecure @Inject constructor(
private val userDetailsDao: UserDetailsDao,
private val hashingUtils: HashingUtils
private val hashingUtils: HashingUtils,
private val symmetricKeyUtils: SymmetricKeyUtils
) : UserDetailsDao {
override suspend fun insertUserDetailsData(userDetailsEntity: UserDetailsEntity) {
userDetailsDao.insertUserDetailsData(hash(userDetailsEntity))
var entity = hash(userDetailsEntity)
entity = encrypt(entity)
userDetailsDao.insertUserDetailsData(entity)
}

override suspend fun getUserDetails(): UserDetailsEntity {
return userDetailsDao.getUserDetails()
}

override suspend fun getHint(): String {
Ni3verma marked this conversation as resolved.
Show resolved Hide resolved
val userDetailsEntity = getUserDetails()
Ni3verma marked this conversation as resolved.
Show resolved Hide resolved
return symmetricKeyUtils.decrypt(userDetailsEntity.hint!!)
}

suspend fun checkPassword(password: String): Boolean {
val userDetailsEntity = getUserDetails()
return hashingUtils.compareHash(password, userDetailsEntity.password)
Expand All @@ -33,4 +42,16 @@ class UserDetailsDaoSecure @Inject constructor(
)
}
}

private fun encrypt(userDetailsEntity: UserDetailsEntity): UserDetailsEntity {
userDetailsEntity.let {
return UserDetailsEntity(
it.key,
it.password,
it.hint?.let { it1 -> symmetricKeyUtils.encrypt(it1) },
it.creationDate,
it.updateDate
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class UserDetailsRepositoryImpl @Inject constructor(
override suspend fun checkPassword(password: String): Boolean {
return userDetailsDaoSecure.checkPassword(password)
}

override suspend fun getHint(): String {
Ni3verma marked this conversation as resolved.
Show resolved Hide resolved
return userDetailsDaoSecure.getHint()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.andryoga.safebox.data.repository.interfaces
interface UserDetailsRepository {
suspend fun insertUserDetailsData(password: String, hint: String)
suspend fun checkPassword(password: String): Boolean
suspend fun getHint(): String
Ni3verma marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/andryoga/safebox/ui/common/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ object Utils {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
}
}

fun switchText(view: TextView, originalText: String, changeToText: String) {
if (view.text == originalText) {
view.text = changeToText
} else {
view.text = originalText
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ChooseMasterPswrdViewModel @Inject constructor(

val pswrd = MutableLiveData<String>("")
val confirmPswrd = MutableLiveData<String>("")
val hint = MutableLiveData<String>("")

val pswrdValidationFailures: LiveData<List<PasswordValidationFailureCode>> =
Transformations.map(pswrd) { currPswrd ->
Expand Down Expand Up @@ -98,7 +99,7 @@ class ChooseMasterPswrdViewModel @Inject constructor(
fun onSaveClick() {
Timber.i("save password clicked")
viewModelScope.launch {
userDetailsRepository.insertUserDetailsData(pswrd.value!!, "ADD HINT IN UI")
userDetailsRepository.insertUserDetailsData(pswrd.value!!, hint.value!!)
encryptedPreferenceProvider.upsertBooleanPref(IS_SIGN_UP_REQUIRED, false)
Timber.i("Added pswrd in db")
_navigateToHome.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.andryoga.safebox.R
import com.andryoga.safebox.databinding.LoginFragmentBinding
import com.andryoga.safebox.ui.common.Utils
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

Expand Down Expand Up @@ -44,6 +45,12 @@ class LoginFragment : Fragment() {

setupObservers()

binding.ShowHintText.setOnClickListener {

Utils.switchText(binding.ShowHintText, getString(R.string.show_hint), getString(R.string.hide_hint))
Utils.switchVisibility(binding.displayHintText, binding.hintDivider)
}

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class LoginViewModel @Inject constructor(
encryptedPreferenceProvider.getBooleanPref(IS_SIGN_UP_REQUIRED, true)

val pswrd = MutableLiveData("Qwerty@@135")
val hint = MutableLiveData("")

init {
viewModelScope.launch {
hint.postValue(userDetailsRepository.getHint())
}
}

private val _isWrongPswrdEntered = MutableLiveData<Boolean>()
val isWrongPswrdEntered: LiveData<Boolean> = _isWrongPswrdEntered
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/res/layout/choose_master_pswrd_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/hint"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/confirm_pswrd">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/hint_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/add_hint"
android:text="@={viewModel.hint}">

</com.google.android.material.textfield.TextInputEditText>

</com.google.android.material.textfield.TextInputLayout>

<TextView
android:id="@+id/length_validation"
style="@style/validationTextViewStyle"
Expand All @@ -80,7 +101,7 @@
android:layout_marginTop="16dp"
android:text="@string/length_validation_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/confirm_pswrd"
app:layout_constraintTop_toBottomOf="@+id/hint"
tools:drawableLeftCompat="@drawable/ic_check_24" />

<TextView
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/login_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@

</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical">

<TextView
android:id="@+id/display_hint_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.hint}"
android:textSize="16sp"
android:visibility="invisible"/>

<View
android:id="@+id/hint_divider"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/colorPrimary"
android:visibility="invisible"/>

<TextView
android:id="@+id/Show_hint_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:text="@string/show_hint"
android:textColor="@color/colorPrimary"/>

</LinearLayout>


<Button
android:id="@+id/save_btn"
android:layout_width="wrap_content"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<string name="bank_account">Bank Account</string>
<string name="bank_card">Bank Card</string>
<string name="secure_note">Secure Note</string>
<string name="add_hint">Add hint</string>
<string name="show_hint">Show hint</string>
<string name="hide_hint">Hide hint</string>
<string name="title">Title <font color='#FF0000'>̽</font></string>
<string name="url">URL</string>
<string name="user_id">User Id <font color='#FF0000'>̽</font></string>
Expand Down