Skip to content

Commit 1e223b1

Browse files
PM-15109 only accept numeric values for account pin lock value (#4359)
1 parent b19e7e1 commit 1e223b1

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/components/toggle/BitwardenUnlockWithPinSwitch.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fun BitwardenUnlockWithPinSwitch(
7979
onUnlockWithPinToggleAction(UnlockWithPinState.Disabled)
8080
pin = ""
8181
},
82+
isPinCreation = true,
8283
)
8384
}
8485

app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/accountsecurity/PinInputDialog.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
4343
* @param onCancelClick A callback for when the "Cancel" button is clicked.
4444
* @param onSubmitClick A callback for when the "Submit" button is clicked.
4545
* @param onDismissRequest A callback for when the dialog is requesting to be dismissed.
46+
* @param isPinCreation A flag for determining if the dialog is being used for PIN creation. We
47+
* want to restrict PINs to numeric values but also support any existing PINs with non-numeric
48+
* characters.
4649
*/
4750
@OptIn(ExperimentalComposeUiApi::class)
4851
@Suppress("LongMethod")
@@ -51,6 +54,7 @@ fun PinInputDialog(
5154
onCancelClick: () -> Unit,
5255
onSubmitClick: (String) -> Unit,
5356
onDismissRequest: () -> Unit,
57+
isPinCreation: Boolean = false,
5458
) {
5559
var pin by remember { mutableStateOf(value = "") }
5660
Dialog(
@@ -107,7 +111,9 @@ fun PinInputDialog(
107111
label = stringResource(id = R.string.pin),
108112
value = pin,
109113
autoFocus = true,
110-
onValueChange = { pin = it },
114+
onValueChange = { newValue ->
115+
pin = newValue.filter { it.isDigit() || !isPinCreation }
116+
},
111117
keyboardType = KeyboardType.Number,
112118
modifier = Modifier
113119
.testTag(tag = "AlertInputField")

app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
388388
composeTestRule
389389
.onAllNodesWithText(text = "PIN")
390390
.filterToOne(hasAnyAncestor(isDialog()))
391-
.performTextInput("PIN")
391+
.performTextInput("1234")
392392
composeTestRule
393393
.onAllNodesWithText(text = "Submit")
394394
.filterToOne(hasAnyAncestor(isDialog()))
@@ -397,7 +397,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
397397
verify {
398398
viewModel.trySendAction(
399399
VaultAddEditAction.Common.PinFido2SetUpSubmit(
400-
pin = "PIN",
400+
pin = "1234",
401401
),
402402
)
403403
}

app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/itemlisting/VaultItemListingScreenTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
17881788
composeTestRule
17891789
.onAllNodesWithText(text = "PIN")
17901790
.filterToOne(hasAnyAncestor(isDialog()))
1791-
.performTextInput("PIN")
1791+
.performTextInput("1234")
17921792
composeTestRule
17931793
.onAllNodesWithText(text = "Submit")
17941794
.filterToOne(hasAnyAncestor(isDialog()))
@@ -1797,7 +1797,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
17971797
verify {
17981798
viewModel.trySendAction(
17991799
VaultItemListingsAction.PinFido2SetUpSubmit(
1800-
pin = "PIN",
1800+
pin = "1234",
18011801
selectedCipherId = selectedCipherId,
18021802
),
18031803
)

0 commit comments

Comments
 (0)