Skip to content

Instantly share code, notes, and snippets.

@CombustibleToast
Last active February 28, 2019 17:24
Show Gist options
  • Save CombustibleToast/4986695ee07f1538a570250577695d75 to your computer and use it in GitHub Desktop.
Save CombustibleToast/4986695ee07f1538a570250577695d75 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<div id='div1'>
<input id='uLetters' type='checkbox' checked>Uppercase Letters</input><br>
<input id='lLetters' type='checkbox' checked>Lowercase Letters</input><br>
<input id='numbers' type='checkbox' checked>Numbers</input><br>
<input id='symbols' type='checkbox' checked>Symbols</input><br>
<input id='length' type='text' placeholder='Length'></input>
<button onclick='main(document.getElementById("length").value)'>Generate</button>
<button onclick='superMain(document.getElementById("length").value)'>SuperPrint</button>
<button onclick='clearPage()'>Clear</button>
</div>
<div id='div2'></div>
<script>
function superMain(length){
clearPage();
for(var i = 0; i < 500; i++){
betterPrint(generatePassword(length));
}
}
function main(length){
clearPage();
betterPrint(generatePassword(length));
}
function fill(){
var chars = [];
if(document.getElementById("numbers").checked){
for(var i = 0; i < 10; i++)
chars.push(i);
}
if(document.getElementById("uLetters").checked){
for(var i = 65; i <= 90; i++)
chars.push(String.fromCharCode(i));
}
if(document.getElementById("lLetters").checked){
for(var i = 97; i <= 122; i++)
chars.push(String.fromCharCode(i));
}
if(document.getElementById("symbols").checked)
chars = chars.concat(['<','>','!','\\','\"','#','$','%','&','/','(',')','*','+','-','.',':',';','=','@','[',']','^','_','`','|','~','?']);
return chars;
}
function generatePassword(length){
var chars = fill();
var pass = "";
for(var i = 0; i < length; i++)
pass += chars[Math.floor(Math.random()*(chars.length))];
return pass;
}
function betterPrint(pass){
var p = document.createElement("p");
p.appendChild(document.createTextNode(pass));
p.setAttribute("id","output");
var div = document.getElementById("div2");
div.appendChild(p);
}
function clearPage(){
var parent = document.getElementById("div2");
while(parent.firstChild)
parent.removeChild(parent.firstChild)
}
function list(){
for(var i = 0; i < 127; i++)
document.writeln(String.fromCharCode(i) + " : " + i + "<br>");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment