Last active
March 22, 2017 10:27
-
-
Save james-jlo-long/8cfcd2cebbd858cbad7b1b11b110dd93 to your computer and use it in GitHub Desktop.
A couple of functions to generate simple passwords. Beware that this is based on Math.random() - it is not cryptographically secure
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
var PW = (function () { | |
"use strict"; | |
var sym = "!£$%^&*()-_=+[{]};:@#~,<.>/?\\|"; | |
var getRand = (n) => Math.floor(Math.random() * n); | |
var basic = () => ( | |
btoa(getRand(Date.now())) | |
.replace(/=+$/, "") | |
.split("") | |
.reverse() | |
.join("") | |
.slice(0, -2) | |
); | |
var strong = function () { | |
var pw = basic().split(""); | |
var times = getRand(pw.length); | |
while (times) { | |
times -= 1; | |
if (Math.random() < 0.5) { | |
pw[getRand(pw.length)] = sym[getRand(sym.length)]; | |
} | |
} | |
return pw.join(""); | |
}; | |
return { | |
basic, | |
strong | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment