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
|
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`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue