Skip to content

Commit

Permalink
Use a min length of 6 for new PIN reminders.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 14, 2020
1 parent dcb5f7b commit 81532ca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static TextWatcher getV2PinWatcher(@NonNull Context context, AlertDialog
if (s == null) return;
String pin = s.toString();
if (TextUtils.isEmpty(pin)) return;
if (pin.length() < KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH) return;
if (pin.length() < KbsConstants.LEGACY_MINIMUM_PIN_LENGTH) return;

if (PinHashing.verifyLocalPinHash(localPinHash, pin)) {
dialog.dismiss();
Expand Down Expand Up @@ -186,9 +186,9 @@ public static void showRegistrationLockPrompt(@NonNull Context context, @NonNull
String pinValue = pin.getText().toString().replace(" ", "");
String repeatValue = repeat.getText().toString().replace(" ", "");

if (pinValue.length() < KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH) {
if (pinValue.length() < KbsConstants.LEGACY_MINIMUM_PIN_LENGTH) {
Toast.makeText(context,
context.getString(R.string.RegistrationLockDialog_the_registration_lock_pin_must_be_at_least_d_digits, KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH),
context.getString(R.string.RegistrationLockDialog_the_registration_lock_pin_must_be_at_least_d_digits, KbsConstants.LEGACY_MINIMUM_PIN_LENGTH),
Toast.LENGTH_LONG).show();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onClick(@NonNull View widget) {
pinEditText.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(String text) {
if (text.length() >= KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH) {
if (text.length() >= KbsConstants.minimumPossiblePinLength()) {
submit.setEnabled(true);
} else {
submit.setEnabled(false);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void verifyPin(@Nullable String pin, @NonNull Callback callback) {
if (pin == null) return;
if (TextUtils.isEmpty(pin)) return;

if (pin.length() < KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH) return;
if (pin.length() < KbsConstants.minimumPossiblePinLength()) return;

if (PinHashing.verifyLocalPinHash(localPinHash, pin)) {
callback.onPinCorrect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

viewModel = initializeViewModel();
viewModel.getUserEntry().observe(getViewLifecycleOwner(), kbsPin -> {
boolean isEntryValid = kbsPin.length() >= KbsConstants.MINIMUM_NEW_PIN_LENGTH;
boolean isEntryValid = kbsPin.length() >= KbsConstants.MINIMUM_PIN_LENGTH;

confirm.setEnabled(isEntryValid);
confirm.setAlpha(isEntryValid ? 1f : 0.5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ private String getLabelText(@NonNull PinKeyboardType keyboard) {
}

private String getPinLengthRestrictionText(@PluralsRes int plurals) {
return requireContext().getResources().getQuantityString(plurals, KbsConstants.MINIMUM_NEW_PIN_LENGTH, KbsConstants.MINIMUM_NEW_PIN_LENGTH);
return requireContext().getResources().getQuantityString(plurals, KbsConstants.MINIMUM_PIN_LENGTH, KbsConstants.MINIMUM_PIN_LENGTH);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.thoughtcrime.securesms.lock.v2;

import org.thoughtcrime.securesms.keyvalue.SignalStore;

public final class KbsConstants {

static final int MINIMUM_NEW_PIN_LENGTH = 6;
public static final int MINIMUM_PIN_LENGTH = 6;
public static final int LEGACY_MINIMUM_PIN_LENGTH = 4;

/** Migrated pins from V1 might be 4 */
public static final int MINIMUM_POSSIBLE_PIN_LENGTH = 4;
private KbsConstants() { }

private KbsConstants() {
public static int minimumPossiblePinLength() {
return SignalStore.kbsValues().hasMigratedToPinsForAll() ? MINIMUM_PIN_LENGTH : LEGACY_MINIMUM_PIN_LENGTH;
}

}

0 comments on commit 81532ca

Please sign in to comment.