Random Passwords
Generate random passwords.
by the_voder
CSS
body {
font-family: 'Courier New', monospace;
margin: 20px;
}
JavaScript
///////////////////////////////////////////////////////////////////
// Create list of passwords using JavaScript string-manipulation //
///////////////////////////////////////////////////////////////////
// Possible password characters
// Now WordPress-safe (I think)
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMMOPQRSTUVWXQZ0123456789()^%*$#!@&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMMOPQRSTUVWXQZ0123456789()^%*$#!@&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMMOPQRSTUVWXQZ0123456789()^%*$#!@&";
// Password length
const len = 24;
// Password count
const count = 100;
// Extend string object with new random "shuffle" method
// https://stackoverflow.com/questions/3943772/how-do-i-shuffle-the-characters-in-a-string-in-javascript
String.prototype.shuffle = function() {
var a = this.split(""),
n = a.length;
for (var i = n - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
return a.join("");
}
// Loop count times creating passwords
for (i = 0; i < count; i++) {
// Apply shuffle to chars string and trim result to length
var password = chars.shuffle().slice(0, len) + "</br>"
$("body").append(password);
}