All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nulabinc.zxcvbn.matchers.RegexMatcher Maven / Gradle / Ivy

Go to download

This is a java port of zxcvbn, which is a JavaScript password strength generator.

There is a newer version: 1.9.0
Show newest version
package com.nulabinc.zxcvbn.matchers;

import com.nulabinc.zxcvbn.WipeableString;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.*;

public class RegexMatcher extends BaseMatcher {

    private static final Map REGEXEN = new HashMap<>();
    static {
        REGEXEN.put("recent_year", "19\\d\\d|200\\d|201\\d|202\\d");
    }

    @Override
    public List execute(CharSequence password) {
        List matches = new ArrayList<>();
        for(Map.Entry regexenRef: REGEXEN.entrySet()) {
            String name = regexenRef.getKey();
            java.util.regex.Matcher rxMatch = Pattern.compile(regexenRef.getValue()).matcher(password);
            while(rxMatch.find()){
                CharSequence token = new WipeableString(rxMatch.group());
                matches.add(MatchFactory.createRegexMatch(
                        rxMatch.start(),
                        rxMatch.start() + token.length() - 1,
                        token,
                        name,
                        rxMatch));
            }
        }
        return this.sorted(matches);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy