diff --git a/src/composables/useDemoAccountGenerator.ts b/src/composables/useDemoAccountGenerator.ts index d0689da..4450988 100644 --- a/src/composables/useDemoAccountGenerator.ts +++ b/src/composables/useDemoAccountGenerator.ts @@ -22,16 +22,29 @@ export function useDemoAccountGenerator() { return password } + // Generate unique username < 20 characters long + function generateUsername() { + const maxLength = 20; + const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 }); + + while (true) { + const username = uniqueNamesGenerator({ + dictionaries: [adjectives, animals, numberDictionary], + separator: '', + length: 3, + style: 'capital' + }); + + if (username.length <= maxLength) { + return username; + } + // otherwise reroll + } + } + // Generate unique username and random password function generateCredentials(): GeneratedCredentials { - // Use only 2 dictionaries to keep username shorter - const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 }); - const username = uniqueNamesGenerator({ - dictionaries: [adjectives, animals, numberDictionary], - separator: '', - length: 3, - style: 'capital' - }) + const username = generateUsername() const password = generateRandomPassword() const email = `${username}@demo.local`