Created
July 6, 2009 14:06
-
-
Save meh/141440 to your computer and use it in GitHub Desktop.
ljs password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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