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 < 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 // Generate unique username and random password
function generateCredentials(): GeneratedCredentials { function generateCredentials(): GeneratedCredentials {
// Use only 2 dictionaries to keep username shorter const username = generateUsername()
const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 });
const username = uniqueNamesGenerator({
dictionaries: [adjectives, animals, numberDictionary],
separator: '',
length: 3,
style: 'capital'
})
const password = generateRandomPassword() const password = generateRandomPassword()
const email = `${username}@demo.local` const email = `${username}@demo.local`