Browse Source

implement generating passwords with digits

feature-password-generator
binsky 3 years ago
parent
commit
5eb63ea2b3
  1. 2
      src/main/java/PasswordGenerator.java
  2. 5
      src/test/java/PasswordGeneratorTest.java

2
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())));

5
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());
}
}
Loading…
Cancel
Save