Add textual representations to password strength meter

This commit is contained in:
Torsten Grote
2024-05-10 13:39:19 -03:00
parent 7d95eb4de6
commit 16385ecafe
2 changed files with 17 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static androidx.core.content.ContextCompat.checkSelfPermission;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.STRONG;
import static org.briarproject.briar.android.util.UiUtils.hideViewOnSmallScreen;
import static org.briarproject.briar.android.util.UiUtils.setError;
import static org.briarproject.briar.android.util.UiUtils.showOnboardingDialog;
@@ -117,17 +118,27 @@ public class SetPasswordFragment extends SetupFragment {
String password2 = passwordConfirmation.getText().toString();
boolean passwordsMatch = password1.equals(password2);
strengthMeter
.setVisibility(password1.length() > 0 ? VISIBLE : INVISIBLE);
strengthMeter.setVisibility(!password1.isEmpty() ? VISIBLE : INVISIBLE);
float strength = viewModel.estimatePasswordStrength(password1);
strengthMeter.setStrength(strength);
boolean strongEnough = strength >= QUITE_WEAK;
if (!password1.isEmpty()) {
if (strength >= STRONG) {
passwordEntryWrapper.setHelperText(
getString(R.string.password_strong));
} else if (strength >= QUITE_WEAK) {
passwordEntryWrapper.setHelperText(
getString(R.string.password_quite_strong));
} else {
passwordEntryWrapper.setHelperTextEnabled(false);
}
}
setError(passwordEntryWrapper, getString(R.string.password_too_weak),
password1.length() > 0 && !strongEnough);
!password1.isEmpty() && !strongEnough);
setError(passwordConfirmationWrapper,
getString(R.string.passwords_do_not_match),
password2.length() > 0 && !passwordsMatch);
!password2.isEmpty() && !passwordsMatch);
boolean enabled = passwordsMatch && strongEnough;
nextButton.setEnabled(enabled);

View File

@@ -17,6 +17,8 @@
<string name="confirm_password">Confirm your password</string>
<string name="name_too_long">Name is too long</string>
<string name="password_too_weak">Password is too weak</string>
<string name="password_quite_strong">Password is okay</string>
<string name="password_strong">Password is strong</string>
<string name="passwords_do_not_match">Passwords do not match</string>
<string name="create_account_button">Create Account</string>
<string name="more_info">More Information</string>