-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatePatternChecker.java
More file actions
39 lines (34 loc) · 1.31 KB
/
DatePatternChecker.java
File metadata and controls
39 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.*;
public class DatePatternChecker implements PasswordPatternChecker {
private final List<String> months;
private final int yearStart;
private final int yearEnd;
public DatePatternChecker(List<String> months, int yearStart, int yearEnd) {
this.months = months;
this.yearStart = yearStart;
this.yearEnd = yearEnd;
}
@Override
public List<Finding> check(String password) {
List<Finding> findings = new ArrayList<>();
String pwLow = password.toLowerCase();
boolean hasDate = password.matches(".*\\b(19|20)\\d{2}\\b.*");
boolean hasMth = months.stream().anyMatch(pwLow::contains);
boolean hasYear = false;
for (int y = yearStart; y <= yearEnd; y++) {
if (password.contains(String.valueOf(y))) { hasYear = true; break; }
}
if (hasDate || hasMth || hasYear) {
findings.add(new Finding(
Finding.Severity.HIGH,
"Pattern data/anno rilevato",
"Date e anni (specialmente di nascita o fondazione) riducono lo spazio di ricerca a poche migliaia di varianti."
));
}
return findings;
}
@Override
public String getName() {
return "Pattern data/anno";
}
}