Skip to content

Instantly share code, notes, and snippets.

@meh
Created July 6, 2009 14:06
Show Gist options
  • Save meh/141440 to your computer and use it in GitHub Desktop.
Save meh/141440 to your computer and use it in GitHub Desktop.
ljs password generator
#! /usr/bin/env ljs
var range = (arguments.shift() || "15-20").split(/-/);
var charset = new RegExp(arguments.shift() || "[a-zA-Z0-9]");
var regex = new RegExp(arguments.shift() || ".");
var length = ((Math.random() * (range[1].toNumber() - range[0].toNumber())) + range[0].toNumber()).ceil();
do {
var password = "";
for (let i = 0; i < length; i++) {
let ch = String.fromCharCode(Math.random() * 200+10);
if (ch.test(charset)) {
password += ch;
}
else {
i--;
}
}
} while (!password.test(regex));
print(password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment