mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Merge branch 'develop' of https://github.com/cryptomator/cryptomator into develop
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user