Skip to content

Instantly share code, notes, and snippets.

@oksuz
Created July 6, 2021 09:52
Show Gist options
  • Save oksuz/c288647350d8abfcc0b11825bcb79725 to your computer and use it in GitHub Desktop.
Save oksuz/c288647350d8abfcc0b11825bcb79725 to your computer and use it in GitHub Desktop.
const randomNumberGenerator = () => String.fromCharCode(parseInt(Math.random() * (57 - 49) + 49, 10));
const randomStringGenerator = () => String.fromCharCode(parseInt(Math.random() * (122 - 97) + 97, 10));
const randomPasswordGenerator = (len = 8, skip = ['l', '0', 'o', 'j']) => {
let password = '';
for (let i = 0; i < len; i++) {
const gen = i < 2 ? randomStringGenerator() : randomNumberGenerator();
if (skip.indexOf(gen) >= 0) {
i--;
continue;
}
password += gen;
}
return password;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment