This commit is contained in:
Sebastian Stenzel
2017-11-02 11:16:41 +01:00
parent a850e8b816
commit a7b036d441
2 changed files with 25 additions and 2 deletions

View File

@@ -14,9 +14,9 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.cryptomator.ui.l10n.Localization;
import com.google.common.base.Strings;
import com.nulabinc.zxcvbn.Zxcvbn;
import javafx.geometry.Insets;
@@ -41,8 +41,10 @@ public class PasswordStrengthUtil {
}
public int computeRate(String password) {
if (StringUtils.isEmpty(password)) {
if (Strings.isNullOrEmpty(password)) {
return -1;
} else if (password.length() > 100) {
return 4; // assume this is strong. zxcvbn memory and runtime depends vastly on the password length
} else {
return zxcvbn.measure(password, sanitizedInputs).getScore();
}

View File

@@ -0,0 +1,21 @@
package org.cryptomator.ui.util;
import org.cryptomator.ui.l10n.Localization;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
public class PasswordStrengthUtilTest {
@Test
public void testLongPasswordsWillBeRatedAsStrong() {
PasswordStrengthUtil util = new PasswordStrengthUtil(Mockito.mock(Localization.class));
StringBuilder longPwBuilder = new StringBuilder();
for (int i = 0; i < 101; i++) {
longPwBuilder.append('x');
}
int strength = util.computeRate(longPwBuilder.toString());
Assert.assertEquals(4, strength);
}
}