#278 Forbid to create a vault with a very bad password

This commit is contained in:
Julian Raufelder 2021-04-29 20:51:16 +02:00
parent af051ccad0
commit e5382b6d52
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
5 changed files with 29 additions and 14 deletions

View File

@ -51,6 +51,14 @@ class ChangePasswordDialog : BaseProgressErrorDialog<ChangePasswordDialog.Callba
changePasswordButton?.let { button ->
et_new_retype_password.nextFocusForwardId = button.id
}
registerOnEditorDoneActionAndPerformButtonClick(et_new_retype_password) { changePasswordButton }
PasswordStrengthUtil() //
.startUpdatingPasswordStrengthMeter(et_new_password, //
progressBarPwStrengthIndicator, //
textViewPwStrengthIndicator, //
changePasswordButton)
}
}
@ -83,11 +91,6 @@ class ChangePasswordDialog : BaseProgressErrorDialog<ChangePasswordDialog.Callba
override fun setupView() {
et_old_password.requestFocus()
registerOnEditorDoneActionAndPerformButtonClick(et_new_retype_password) { changePasswordButton }
PasswordStrengthUtil() //
.startUpdatingPasswortStrengthMeter(et_new_password, //
progressBarPwStrengthIndicator, //
textViewPwStrengthIndicator)
dialog?.let { showKeyboard(it) }
}

View File

@ -29,9 +29,10 @@ class SetPasswordFragment : BaseFragment() {
}
false
}
passwordStrengthUtil.startUpdatingPasswortStrengthMeter(passwordEditText, //
passwordStrengthUtil.startUpdatingPasswordStrengthMeter(passwordEditText, //
progressBarPwStrengthIndicator, //
textViewPwStrengthIndicator)
textViewPwStrengthIndicator, //
createVaultButton)
passwordEditText.requestFocus()
}

View File

@ -14,13 +14,21 @@ enum class PasswordStrength(val score: Int, val description: Int, val color: Int
companion object {
private const val MIN_PASSWORD_LENGTH = 8
private val zxcvbn = Zxcvbn()
fun forPassword(password: String, sanitizedInputs: List<String>): PasswordStrength {
return if (password.isEmpty()) {
EMPTY
} else {
forScore(zxcvbn.measure(password, sanitizedInputs).score).orElse(EMPTY)
return when {
password.isEmpty() -> {
EMPTY
}
password.length < MIN_PASSWORD_LENGTH -> {
EXTREMELY_WEAK
}
else -> {
forScore(zxcvbn.measure(password, sanitizedInputs).score).orElse(EMPTY)
}
}
}

View File

@ -1,6 +1,7 @@
package org.cryptomator.presentation.util;
import android.graphics.PorterDuff;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -40,9 +41,10 @@ public class PasswordStrengthUtil {
public PasswordStrengthUtil() {
}
public void startUpdatingPasswortStrengthMeter(EditText passwordInput, //
public void startUpdatingPasswordStrengthMeter(EditText passwordInput, //
final ProgressBar strengthMeter, //
final TextView strengthLabel) {
final TextView strengthLabel, //
final Button button) {
RxTextView.textChanges(passwordInput) //
.observeOn(Schedulers.computation()) //
.map(password -> PasswordStrength.Companion.forPassword(password.toString(), SANITIZED_INPUTS)) //
@ -51,6 +53,7 @@ public class PasswordStrengthUtil {
strengthMeter.getProgressDrawable().setColorFilter(ResourceHelper.Companion.getColor(strength.getColor()), PorterDuff.Mode.SRC_IN);
strengthLabel.setText(strength.getDescription());
strengthMeter.setProgress(strength.getScore() + 1);
button.setEnabled(strength.getScore() > PasswordStrength.EXTREMELY_WEAK.getScore());
});
}
}

View File

@ -187,7 +187,7 @@
<string name="screen_set_password_password_label" translatable="false">@string/screen_webdav_settings_password_label</string>
<string name="screen_set_password_retype_password_label">Retype password</string>
<string name="screen_set_password_strength_indicator_0">Very weak</string>
<string name="screen_set_password_strength_indicator_0">Too weak to create a vault</string>
<string name="screen_set_password_strength_indicator_1">Weak</string>
<string name="screen_set_password_strength_indicator_2">Fair</string>
<string name="screen_set_password_strength_indicator_3">Strong</string>