本文整理了Java中com.nulabinc.zxcvbn.Zxcvbn.measure()
方法的一些代码示例,展示了Zxcvbn.measure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Zxcvbn.measure()
方法的具体详情如下:
包路径:com.nulabinc.zxcvbn.Zxcvbn
类名称:Zxcvbn
方法名:measure
暂无
代码示例来源:origin: nulab/zxcvbn4j
public Strength measure(String password) {
return measure(password, null);
}
代码示例来源:origin: com.nulab-inc/zxcvbn
public Strength measure(String password) {
return measure(password, null);
}
代码示例来源:origin: iterate-ch/cyberduck
public Strength getScore(final String password) {
if(StringUtils.isEmpty(password)) {
return Strength.veryweak;
}
else {
final int score = zxcvbn.measure(password, Collections.singletonList(
PreferencesFactory.get().getProperty("application.name"))).getScore();
switch(score) {
case 0:
return Strength.veryweak;
case 1:
return Strength.weak;
case 2:
return Strength.fair;
case 3:
return Strength.strong;
case 4:
default:
return Strength.verystrong;
}
}
}
代码示例来源:origin: pwm-project/pwm
public static int judgePasswordStrengthUsingZxcvbnAlgorithm(
final Configuration configuration,
final String password
)
{
final Zxcvbn zxcvbn = new Zxcvbn();
final Strength strength = zxcvbn.measure( password );
final int zxcvbnScore = strength.getScore();
// zxcvbn returns a score of 0-4 (see: https://github.com/dropbox/zxcvbn)
switch ( zxcvbnScore )
{
case 4:
return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_VERY_STRONG ) );
case 3:
return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_STRONG ) );
case 2:
return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_GOOD ) );
case 1:
return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_WEAK ) );
default:
return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_VERY_WEAK ) );
}
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testMeasure() throws Exception {
// add password to the engine scope
engine.put("pwd", password);
@SuppressWarnings("unchecked")
Map<String, Object> result = (Map<String, Object>) engine.eval("zxcvbn(pwd);");
Object score = result.get("score");
int jsScore;
// nashorn returns int, rhino returns double
if (score instanceof Double) {
jsScore = ((Double) score).intValue();
} else {
jsScore = (int) score;
}
int javaScore = zxcvbn.measure(password).getScore();
Assert.assertEquals("Password score difference for " + password, jsScore, javaScore);
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testWarning() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback();
ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.ROOT);
String expectedWarningL10n = expectedWarning.length() > 0 ? resourceBundle.getString(expectedWarning) : "";
Assert.assertEquals("Unexpected warning", expectedWarningL10n, feedback.getWarning(Locale.ENGLISH));
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testJapaneseWarning() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback();
ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.JAPANESE);
String expectedWarningL10n = expectedWarning.length() > 0 ? resourceBundle.getString(expectedWarning) : "";
Assert.assertEquals("Unexpected warning", expectedWarningL10n, feedback.getWarning(Locale.JAPANESE));
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testSuggestions() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback();
ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.ROOT);
String[] expectedSuggestionsL10n = new String[expectedSuggestions.length];
for (int i = 0; i < expectedSuggestions.length; i++) {
String expectedSuggestion = expectedSuggestions[i];
expectedSuggestionsL10n[i] = resourceBundle.getString(expectedSuggestion);
}
Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestionsL10n, feedback.getSuggestions(Locale.ENGLISH).toArray());
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testJapaneseSuggestions() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback();
ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.JAPANESE);
String[] expectedSuggestionsL10n = new String[expectedSuggestions.length];
for (int i = 0; i < expectedSuggestions.length; i++) {
String expectedSuggestion = expectedSuggestions[i];
expectedSuggestionsL10n[i] = resourceBundle.getString(expectedSuggestion);
}
Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestionsL10n, feedback.getSuggestions(Locale.JAPANESE).toArray());
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testMeasure() throws Exception {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
assertEquals("Unexpected error. Password is " + password, password, strength.getPassword());
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testUnknownSuggestions() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback().withResourceBundle(null);
Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestions, feedback.getSuggestions().toArray());
}
代码示例来源:origin: nulab/zxcvbn4j
@Test
public void testUnknownWarning() {
Zxcvbn zxcvbn = new Zxcvbn();
Strength strength = zxcvbn.measure(password);
Feedback feedback = strength.getFeedback().withResourceBundle(null);
Assert.assertEquals("Unexpected warning", expectedWarning, feedback.getWarning());
}
内容来源于网络,如有侵权,请联系作者删除!