Browse Source

implement method to test if a password is part of the german wordlist

feature-password-validator-2
binsky 3 years ago
parent
commit
7588794f5f
  1. 18
      src/main/java/PasswordValidator.java
  2. 6
      src/test/java/PasswordValidatorTest.java

18
src/main/java/PasswordValidator.java

@ -132,4 +132,22 @@ public class PasswordValidator {
return false; return false;
} }
public static boolean isInWordlist(String password) {
try {
ResourceApi resourceApi = new ResourceApi();
String germanWordlist = resourceApi.getFileFromResourceAsString("german_wordlist.txt");
BufferedReader bufReader = new BufferedReader(new StringReader(germanWordlist));
String line = null;
while ((line = bufReader.readLine()) != null) {
if (line.contains(password)) {
return true;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
} }

6
src/test/java/PasswordValidatorTest.java

@ -89,4 +89,10 @@ class PasswordValidatorTest {
assertFalse(PasswordValidator.isPwned("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+")); assertFalse(PasswordValidator.isPwned("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+"));
assertFalse(PasswordValidator.isPwned("")); assertFalse(PasswordValidator.isPwned(""));
} }
@Test
void isInWordlist() {
assertTrue(PasswordValidator.isInWordlist("Sonne"));
assertFalse(PasswordValidator.isInWordlist("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+"));
}
} }
Loading…
Cancel
Save