make sure username < 20 characters

This commit is contained in:
padreug 2025-09-04 11:51:00 +02:00
parent c082cae156
commit 93ffb8bf32

View file

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