com.nulabinc.zxcvbn.matchers.RegexMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zxcvbn Show documentation
Show all versions of zxcvbn Show documentation
This is a java port of zxcvbn, which is a JavaScript password strength generator.
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);
}
}