Skip to content

Commit

Permalink
Require at least 4 digits during registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed Feb 3, 2020
1 parent c21d486 commit b29b3d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.res.Resources;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -35,6 +34,9 @@ public final class RegistrationLockFragment extends BaseRegistrationFragment {

private static final String TAG = Log.tag(RegistrationLockFragment.class);

/** Applies to both V1 and V2 pins, because some V2 pins may have been migrated from V1. */
private static final int MINIMUM_PIN_LENGTH = 4;

private EditText pinEntry;
private View forgotPin;
private CircularProgressButton pinButton;
Expand Down Expand Up @@ -129,11 +131,17 @@ private PinKeyboardType getPinEntryKeyboardType() {
private void handlePinEntry() {
final String pin = pinEntry.getText().toString();

if (TextUtils.isEmpty(pin) || TextUtils.isEmpty(pin.replace(" ", ""))) {
int trimmedLength = pin.replace(" ", "").length();
if (trimmedLength == 0) {
Toast.makeText(requireContext(), R.string.RegistrationActivity_you_must_enter_your_registration_lock_PIN, Toast.LENGTH_LONG).show();
return;
}

if (trimmedLength < MINIMUM_PIN_LENGTH) {
Toast.makeText(requireContext(), getString(R.string.RegistrationActivity_your_pin_has_at_least_d_digits_or_characters, MINIMUM_PIN_LENGTH), Toast.LENGTH_LONG).show();
return;
}

RegistrationViewModel model = getModel();
RegistrationService registrationService = RegistrationService.getInstance(model.getNumber().getE164Number(), model.getRegistrationSecret());
TokenResponse tokenResponse = model.getKeyBackupCurrentToken();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@
<string name="preferences_app_protection__registration_lock_pin">Registration Lock PIN</string>
<string name="preferences_app_protection__registration_lock">Registration Lock</string>
<string name="RegistrationActivity_you_must_enter_your_registration_lock_PIN">You must enter your Registration Lock PIN</string>
<string name="RegistrationActivity_your_pin_has_at_least_d_digits_or_characters">Your pin has at least %d digits or characters</string>
<string name="RegistrationActivity_incorrect_registration_lock_pin">Incorrect Registration Lock PIN</string>
<string name="RegistrationActivity_too_many_attempts">Too many attempts</string>
<string name="RegistrationActivity_you_have_made_too_many_incorrect_registration_lock_pin_attempts_please_try_again_in_a_day">You\'ve made too many incorrect Registration Lock PIN attempts. Please try again in a day.</string>
Expand Down

0 comments on commit b29b3d0

Please sign in to comment.