• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nulab / zxcvbn4j / #141

pending completion
#141

push

github-actions

web-flow
Merge pull request #135 from manchilop/master

Added feedback messages translated into Spanish

1392 of 1507 relevant lines covered (92.37%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/src/main/java/com/nulabinc/zxcvbn/guesses/RegexGuess.java
1
package com.nulabinc.zxcvbn.guesses;
2

3
import com.nulabinc.zxcvbn.Context;
4
import com.nulabinc.zxcvbn.WipeableString;
5
import com.nulabinc.zxcvbn.matchers.Match;
6

7
import java.util.HashMap;
8
import java.util.Map;
9

10
public class RegexGuess extends BaseGuess {
11

12
    private static final Map<String, Integer> CHAR_CLASS_BASES = new HashMap<>();
1✔
13
    static {
14
        CHAR_CLASS_BASES.put("alpha_lower", 26);
1✔
15
        CHAR_CLASS_BASES.put("alpha_upper", 26);
1✔
16
        CHAR_CLASS_BASES.put("alpha", 52);
1✔
17
        CHAR_CLASS_BASES.put("alphanumeric", 62);
1✔
18
        CHAR_CLASS_BASES.put("digits", 10);
1✔
19
        CHAR_CLASS_BASES.put("symbols", 33);
1✔
20
    }
1✔
21

22
    protected RegexGuess(final Context context) {
23
        super(context);
1✔
24
    }
1✔
25

26
    @Override
27
    public double exec(Match match) {
28
        if (CHAR_CLASS_BASES.containsKey(match.regexName)) {
1✔
29
            return Math.pow(CHAR_CLASS_BASES.get(match.regexName), match.tokenLength());
×
30
        } else if ("recent_year".equals(match.regexName)) {
1✔
31
            double yearSpace = Math.abs(parseInt(match.token) - REFERENCE_YEAR);
1✔
32
            yearSpace = Math.max(yearSpace, MIN_YEAR_SPACE);
1✔
33
            return yearSpace;
1✔
34
        }
35
        return 0;
×
36
    }
37

38
    private static int parseInt(CharSequence s) {
39
        int result = 0;
1✔
40
        try {
41
            result = WipeableString.parseInt(s);
1✔
42
        } catch (NumberFormatException e) {
×
43
            // ignore
44
        }
1✔
45
        return result;
1✔
46
    }
47
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc