Added password length check while creating backups #770

This commit is contained in:
Ullas-Aithal 2021-02-20 13:12:00 +05:30
parent dfc788cd29
commit 0fb27f3a5c
2 changed files with 30 additions and 10 deletions

View file

@ -13,9 +13,11 @@ import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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.Tools;
public class PasswordEntryDialog extends AppCompatDialog
@ -27,12 +29,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 toShortWarning;
public PasswordEntryDialog(Context context, Mode newMode, boolean blockAccessibility, boolean blockAutofill, PasswordEnteredCallback newCallback) {
super(context, Tools.getThemeResource(context, R.attr.dialogTheme));
@ -43,6 +46,8 @@ public class PasswordEntryDialog extends AppCompatDialog
TextInputLayout passwordLayout = findViewById(R.id.passwordInputLayout);
passwordInput = findViewById(R.id.passwordInput);
passwordConfirm = findViewById(R.id.passwordConfirm);
toShortWarning = findViewById(R.id.toShortWarning);
toShortWarning.setText(getContext().getString(R.string.settings_label_short_password, Constants.AUTH_MIN_PASSWORD_LENGTH));
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
if (blockAccessibility) {
@ -56,9 +61,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;
@ -76,10 +82,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) {
toShortWarning.setVisibility(View.GONE);
if (TextUtils.equals(passwordInput.getEditableText(), passwordConfirm.getEditableText()))
okButton.setEnabled(true);
}
else {
toShortWarning.setVisibility(View.VISIBLE);
okButton.setEnabled(false);
}
}
public void afterTextChanged(Editable s) {}

View file

@ -33,6 +33,15 @@
android:hint="@string/dialog_label_confirm_password"
android:inputType="textPassword" />
<TextView
android:id="@+id/toShortWarning"
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"