public List<String> getSuggestions() { return getSuggestions(Locale.getDefault()); }
public String getWarning() { return getWarning(Locale.getDefault()); }
private static Feedback getMatchFeedback(Match match, boolean isSoleMatch) { switch (match.pattern) { case Dictionary: return getDictionaryMatchFeedback(match, isSoleMatch); case Spatial: return new Feedback(match.turns == 1 ? SPATIAL_WARNING_STRAIGHT_ROWS_OF_KEYS : SPATIAL_WARNING_SHORT_KEYBOARD_PATTERNS, ); case Repeat: return new Feedback(match.baseToken.length() == 1 ? REPEAT_WARNING_LIKE_AAA : REPEAT_WARNING_LIKE_ABCABCABC, ); case Sequence: return new Feedback(SEQUENCE_WARNING_LIKE_ABCOR6543, EXTRA_SUGGESTIONS_ADD_ANOTHER_WORD, SEQUENCE_SUGGESTIONS_AVOID_SEQUENCES ); case Regex: return new Feedback("recent_year".equals(match.regexName) ? REGEX_WARNING_RECENT_YEARS : null, ); case Date: return new Feedback( DATE_WARNING_DATES,
public String getWarning(Locale locale) { if (this.warning == null) { return ""; } ResourceBundle messages = resolveResourceBundle(locale); return l10n(messages, this.warning); }
static Feedback getFeedback(int score, List<Match> sequence) { if (sequence.size() == 0) { return getFeedbackWithoutWarnings( DEFAULT_SUGGESTIONS_USE_FEW_WORDS, DEFAULT_SUGGESTIONS_NO_NEED_SYMBOLS); } if (score > 2) { return getEmptyFeedback(); } Match longestMatch = sequence.get(0); if (sequence.size() > 1) { for (Match match : sequence.subList(1, sequence.size() - 1)) { if (match.token.length() > longestMatch.token.length()) longestMatch = match; } } return getMatchFeedback(longestMatch, sequence.size() == 1); }
@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()); }
@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()); }
private static Feedback getEmptyFeedback() { return new Feedback(null); }
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
static Feedback getFeedback(int score, List<Match> sequence) { if (sequence.size() == 0) { return getFeedbackWithoutWarnings( DEFAULT_SUGGESTIONS_USE_FEW_WORDS, DEFAULT_SUGGESTIONS_NO_NEED_SYMBOLS); } if (score > 2) { return getEmptyFeedback(); } Match longestMatch = sequence.get(0); if (sequence.size() > 1) { for (Match match : sequence.subList(1, sequence.size() - 1)) { if (match.token.length() > longestMatch.token.length()) longestMatch = match; } } return getMatchFeedback(longestMatch, sequence.size() == 1); }
public String getWarning(Locale locale) { if (this.warning == null) { return ""; } ResourceBundle messages = resolveResourceBundle(locale); return l10n(messages, this.warning); }
private static Feedback getFeedbackWithoutWarnings(String... suggestions) { return new Feedback(null, suggestions); }
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
private static Feedback getMatchFeedback(Match match, boolean isSoleMatch) { switch (match.pattern) { case Dictionary: return getDictionaryMatchFeedback(match, isSoleMatch); case Spatial: return new Feedback(match.turns == 1 ? SPATIAL_WARNING_STRAIGHT_ROWS_OF_KEYS : SPATIAL_WARNING_SHORT_KEYBOARD_PATTERNS, ); case Repeat: return new Feedback(match.baseToken.length() == 1 ? REPEAT_WARNING_LIKE_AAA : REPEAT_WARNING_LIKE_ABCABCABC, ); case Sequence: return new Feedback(SEQUENCE_WARNING_LIKE_ABCOR6543, EXTRA_SUGGESTIONS_ADD_ANOTHER_WORD, SEQUENCE_SUGGESTIONS_AVOID_SEQUENCES ); case Regex: return new Feedback("recent_year".equals(match.regexName) ? REGEX_WARNING_RECENT_YEARS : null, ); case Date: return new Feedback( DATE_WARNING_DATES,
public List<String> getSuggestions(Locale locale) { List<String> suggestionTexts = new ArrayList<>(this.suggestions.length); ResourceBundle messages = resolveResourceBundle(locale); for (String suggestion : this.suggestions) { suggestionTexts.add(l10n(messages, suggestion)); } return suggestionTexts; }
public String getWarning() { return getWarning(Locale.getDefault()); }
public List<String> getSuggestions() { return getSuggestions(Locale.getDefault()); }
private static Feedback getEmptyFeedback() { return new Feedback(null); }
public List<String> getSuggestions(Locale locale) { List<String> suggestionTexts = new ArrayList<>(this.suggestions.length); ResourceBundle messages = resolveResourceBundle(locale); for (String suggestion : this.suggestions) { suggestionTexts.add(l10n(messages, suggestion)); } return suggestionTexts; }
@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)); }