diff --git a/src/main/java/PasswordGenerator.java b/src/main/java/PasswordGenerator.java index bab7e6f..0744c31 100644 --- a/src/main/java/PasswordGenerator.java +++ b/src/main/java/PasswordGenerator.java @@ -4,6 +4,7 @@ public class PasswordGenerator { final String lowercaseCharacters = "abcdefghjkmnpqrstuvwxyz"; final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; + final String digits = "0123456789"; int length = 12; @@ -22,6 +23,7 @@ public class PasswordGenerator { characterPool += lowercaseCharacters; characterPool += uppercaseCharacters; + characterPool += digits; for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); diff --git a/src/test/java/PasswordGeneratorTest.java b/src/test/java/PasswordGeneratorTest.java index 57192f3..7f9874c 100644 --- a/src/test/java/PasswordGeneratorTest.java +++ b/src/test/java/PasswordGeneratorTest.java @@ -33,4 +33,9 @@ class PasswordGeneratorTest { void testPasswordUppercaseRequirement() { assertTrue(Pattern.compile("^(?=.*[A-Z]).+$").matcher(passwordGenerator.generateRandomPassword()).matches()); } + + @Test + void testPasswordDigitsRequirement() { + assertTrue(Pattern.compile("^(?=.*\\d).+$").matcher(passwordGenerator.generateRandomPassword()).matches()); + } }