Skip to content

Instantly share code, notes, and snippets.

@th3terrorist
Created October 16, 2022 15:29
Show Gist options
  • Save th3terrorist/230fb35cb5a0c6273107659d0773ddd0 to your computer and use it in GitHub Desktop.
Save th3terrorist/230fb35cb5a0c6273107659d0773ddd0 to your computer and use it in GitHub Desktop.
Very safe password gen
import crypto from "crypto";
let randGenData = {
index: 0,
bytes: [],
poolSize: 512
};
// Generates a word by [' ', ~) from https://www.asciitable.com/
const genRandPass = (length) => {
const genRandValue = () => {
if (randGenData.index >= randGenData.bytes.length) {
randGenData.index = 0;
randGenData.bytes = crypto.randomBytes(randGenData.poolSize);
}
return randGenData.bytes[randGenData.index++];
}
let pass = "";
for (let _ = 0; _ < length; ++_) {
let randvalue = genRandValue() % 94;
pass += String.fromCharCode(33 + randvalue);
}
return pass;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment