UPD: Adding camelcase support and shorten password length

This commit is contained in:
xpk 2023-12-21 16:39:49 +08:00
parent 822b346df0
commit 9dd4bc0b4e
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
3 changed files with 6 additions and 2 deletions

Binary file not shown.

View File

@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List;
class PasswordGenerator {
private static final int DEFAULT_PASSWORD_LENGTH = 4;
private static final int DEFAULT_PASSWORD_LENGTH = 3;
public static void main(String[] args) {
try {
@ -41,11 +41,15 @@ class PasswordGenerator {
for (int i = 0; i < length; i++) {
int randomIndex = random.nextInt(dictionary.size());
String word = dictionary.get(randomIndex);
passwordBuilder.append(word);
passwordBuilder.append(toCamelCase(word));
if ( i < length-1) {
passwordBuilder.append("/");
}
}
return passwordBuilder.toString();
}
private static String toCamelCase(String inputString) {
return inputString.substring(0,1).toUpperCase() + inputString.substring(1).toLowerCase();
}
}

Binary file not shown.