From 7588794f5f38f90a4914770d1e14467d937fb8f8 Mon Sep 17 00:00:00 2001 From: binsky Date: Mon, 14 Feb 2022 19:57:25 +0100 Subject: [PATCH] implement method to test if a password is part of the german wordlist --- src/main/java/PasswordValidator.java | 18 ++++++++++++++++++ src/test/java/PasswordValidatorTest.java | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/PasswordValidator.java b/src/main/java/PasswordValidator.java index ed10c06..5c63f9c 100644 --- a/src/main/java/PasswordValidator.java +++ b/src/main/java/PasswordValidator.java @@ -132,4 +132,22 @@ public class PasswordValidator { 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; + } } diff --git a/src/test/java/PasswordValidatorTest.java b/src/test/java/PasswordValidatorTest.java index 4755cc1..44657e1 100644 --- a/src/test/java/PasswordValidatorTest.java +++ b/src/test/java/PasswordValidatorTest.java @@ -89,4 +89,10 @@ class PasswordValidatorTest { assertFalse(PasswordValidator.isPwned("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+")); assertFalse(PasswordValidator.isPwned("")); } + + @Test + void isInWordlist() { + assertTrue(PasswordValidator.isInWordlist("Sonne")); + assertFalse(PasswordValidator.isInWordlist("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+")); + } }