Skip to content
Snippets Groups Projects
Unverified Commit df81b2de authored by Nicolò Pretto's avatar Nicolò Pretto Committed by GitHub
Browse files

fix(sdk): make sure generated password has at least one number, one upper case...

fix(sdk): make sure generated password has at least one number, one upper case and one lower case character to avoid issues with password policies (#46737)
parent 7fd0d802
No related merge requests found
export function generateRandomDemoPassword(): string {
const chars = "abcdefghijklmnopqrstuvwxyz";
const upperCaseChars = chars.toUpperCase();
const numbers = "0123456789";
const allChars = chars + chars.toUpperCase() + numbers;
const allChars = chars + upperCaseChars + numbers;
const length = 14;
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * allChars.length);
password += allChars[randomIndex];
//make sure we have at least 1 number, one upper case and one lower case character
password += pickRandom(chars);
password += pickRandom(upperCaseChars);
password += pickRandom(numbers);
for (let i = password.length; i < length; i++) {
password += pickRandom(allChars);
}
return password;
return shuffle(password);
}
const pickRandom = (arr: string) => arr[Math.floor(Math.random() * arr.length)];
const shuffle = (arr: string) =>
arr
.split("")
.sort(() => Math.random() - 0.5)
.join("");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment