make sure username < 20 characters
This commit is contained in:
parent
c082cae156
commit
93ffb8bf32
1 changed files with 21 additions and 8 deletions
|
|
@ -22,16 +22,29 @@ export function useDemoAccountGenerator() {
|
|||
return password
|
||||
}
|
||||
|
||||
// Generate unique username and random password
|
||||
function generateCredentials(): GeneratedCredentials {
|
||||
// Use only 2 dictionaries to keep username shorter
|
||||
// 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 {
|
||||
const username = generateUsername()
|
||||
|
||||
const password = generateRandomPassword()
|
||||
const email = `${username}@demo.local`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue