Merge pull request #771 from Ullas-Aithal/feature/BackupsPasswdLengthCheck
Added password length check while creating backups #770
This commit is contained in:
commit
095212d09d
4 changed files with 34 additions and 16 deletions
|
@ -18,6 +18,7 @@ import android.widget.TextView;
|
|||
|
||||
import org.shadowice.flocke.andotp.R;
|
||||
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
|
||||
import org.shadowice.flocke.andotp.Utilities.Constants;
|
||||
import org.shadowice.flocke.andotp.Utilities.EditorActionHelper;
|
||||
import org.shadowice.flocke.andotp.Utilities.Tools;
|
||||
|
||||
|
@ -30,12 +31,13 @@ public class PasswordEntryDialog extends AppCompatDialog
|
|||
void onPasswordEntered(String newPassword);
|
||||
}
|
||||
|
||||
private Mode dialogMode;
|
||||
private PasswordEnteredCallback callback;
|
||||
private final Mode dialogMode;
|
||||
private final PasswordEnteredCallback callback;
|
||||
|
||||
private TextInputEditText passwordInput;
|
||||
private EditText passwordConfirm;
|
||||
private Button okButton;
|
||||
private final TextInputEditText passwordInput;
|
||||
private final EditText passwordConfirm;
|
||||
private final Button okButton;
|
||||
private final TextView tooShortWarning;
|
||||
|
||||
public PasswordEntryDialog(Context context, Mode newMode, boolean blockAccessibility, boolean blockAutofill, PasswordEnteredCallback newCallback) {
|
||||
super(context, Tools.getThemeResource(context, R.attr.dialogTheme));
|
||||
|
@ -46,6 +48,8 @@ public class PasswordEntryDialog extends AppCompatDialog
|
|||
TextInputLayout passwordLayout = findViewById(R.id.passwordInputLayout);
|
||||
passwordInput = findViewById(R.id.passwordInput);
|
||||
passwordConfirm = findViewById(R.id.passwordConfirm);
|
||||
tooShortWarning = findViewById(R.id.tooShortWarning);
|
||||
tooShortWarning.setText(getContext().getString(R.string.settings_label_short_password, Constants.AUTH_MIN_PASSWORD_LENGTH));
|
||||
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||
|
||||
if (blockAccessibility) {
|
||||
|
@ -59,9 +63,10 @@ public class PasswordEntryDialog extends AppCompatDialog
|
|||
}
|
||||
|
||||
okButton = findViewById(R.id.buttonOk);
|
||||
Button cancelButton = findViewById(R.id.buttonCancel);
|
||||
|
||||
okButton.setOnClickListener(this);
|
||||
okButton.setEnabled(false);
|
||||
|
||||
Button cancelButton = findViewById(R.id.buttonCancel);
|
||||
cancelButton.setOnClickListener(this);
|
||||
|
||||
this.callback = newCallback;
|
||||
|
@ -81,11 +86,15 @@ public class PasswordEntryDialog extends AppCompatDialog
|
|||
|
||||
// TextWatcher
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (TextUtils.equals(passwordInput.getEditableText(), passwordConfirm.getEditableText()))
|
||||
okButton.setEnabled(true);
|
||||
else
|
||||
if (passwordInput.getEditableText().length() >= Constants.AUTH_MIN_PASSWORD_LENGTH) {
|
||||
tooShortWarning.setVisibility(View.GONE);
|
||||
okButton.setEnabled(TextUtils.equals(passwordInput.getEditableText(), passwordConfirm.getEditableText()));
|
||||
}
|
||||
else {
|
||||
tooShortWarning.setVisibility(View.VISIBLE);
|
||||
okButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void afterTextChanged(Editable s) {}
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class CredentialsPreference extends DialogPreference
|
|||
private TextInputLayout passwordLayout;
|
||||
private TextInputEditText passwordInput;
|
||||
private EditText passwordConfirm;
|
||||
private TextView toShortWarning;
|
||||
private TextView tooShortWarning;
|
||||
|
||||
private Button btnSave;
|
||||
|
||||
|
@ -141,7 +141,7 @@ public class CredentialsPreference extends DialogPreference
|
|||
passwordConfirm.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
|
||||
}
|
||||
|
||||
toShortWarning = view.findViewById(R.id.toShortWarning);
|
||||
tooShortWarning = view.findViewById(R.id.tooShortWarning);
|
||||
|
||||
passwordInput.addTextChangedListener(this);
|
||||
passwordConfirm.addTextChangedListener(this);
|
||||
|
@ -231,13 +231,13 @@ public class CredentialsPreference extends DialogPreference
|
|||
String password = passwordInput.getEditableText().toString();
|
||||
|
||||
if (password.length() >= minLength) {
|
||||
toShortWarning.setVisibility(View.GONE);
|
||||
tooShortWarning.setVisibility(View.GONE);
|
||||
String confirm = passwordConfirm.getEditableText().toString();
|
||||
|
||||
boolean canSave = !password.isEmpty() && !confirm.isEmpty() && password.equals(confirm);
|
||||
btnSave.setEnabled(canSave);
|
||||
} else {
|
||||
toShortWarning.setVisibility(View.VISIBLE);
|
||||
tooShortWarning.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ public class CredentialsPreference extends DialogPreference
|
|||
|
||||
minLength = isPassword ? Constants.AUTH_MIN_PASSWORD_LENGTH : Constants.AUTH_MIN_PIN_LENGTH;
|
||||
int shortWarningRes = isPassword ? R.string.settings_label_short_password : R.string.settings_label_short_pin;
|
||||
toShortWarning.setText(getContext().getString(shortWarningRes, minLength));
|
||||
tooShortWarning.setText(getContext().getString(shortWarningRes, minLength));
|
||||
|
||||
passwordInput.requestFocus();
|
||||
UIHelper.showKeyboard(getContext(), passwordInput);
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
android:autofillHints="password" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toShortWarning"
|
||||
android:id="@+id/tooShortWarning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
|
|
|
@ -33,6 +33,15 @@
|
|||
android:hint="@string/dialog_label_confirm_password"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tooShortWarning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:visibility="visible"
|
||||
android:textAlignment="center"
|
||||
android:text="@string/settings_label_short_password" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue