Browse Source

refactor isInWordlist test and implementation

feature-password-validator-2
binsky 3 years ago
parent
commit
64d311038b
  1. 4
      src/main/java/PasswordValidator.java
  2. 3
      src/test/java/PasswordValidatorTest.java

4
src/main/java/PasswordValidator.java

@ -4,6 +4,7 @@ import java.io.StringReader;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import java.util.regex.Pattern;
public class PasswordValidator {
@ -135,12 +136,13 @@ public class PasswordValidator {
public static boolean isInWordlist(String password) {
try {
String lowerPassword = password.toLowerCase();
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)) {
if (lowerPassword.contains(line.trim().toLowerCase())) {
return true;
}
}

3
src/test/java/PasswordValidatorTest.java

@ -92,7 +92,8 @@ class PasswordValidatorTest {
@Test
void isInWordlist() {
assertTrue(PasswordValidator.isInWordlist("Sonne"));
assertTrue(PasswordValidator.isInWordlist("Sonnenblume"));
assertTrue(PasswordValidator.isInWordlist("_Sonnenblume123"));
assertFalse(PasswordValidator.isInWordlist("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+"));
}
}
Loading…
Cancel
Save