Javascript and HTML Password Generator
Posted: Mon Aug 12, 2013 2:29 pm
Hello guys i just made my first javascript real coding with HTML and i decided to create a random password generator.
It's totally random and doesn't send it anywhere or store anywhere besides the div random and that's it.
Update: Added Symbols with a probability of 10%
Letters: 50%
Numbers: 40%
Here's the source:
Here's a archive with INDEX and CSS: http://www.oryzhon.com/random.rar
I've used a javascript lib for the hashing in case some people prefer hashed its a little more random then the others. And as for the normal randoming it's all my work, a bit newby but it creates some cool passwords.
btw
var um, dois, trez, quatro, cinco, seis, sete, oito, nove, dez, onze, doze, treze, catorze, quinze;
this means one, two, three, till fifteen in my language so go ahead and feel free to pass it to english or something if you want.
Here's a demo in my website: http://www.oryzhon.com/random
Just sharing with you guys so feel free to use it if you want.. I didn't felt like adding symbols but i should i know. This was just to code something in javascript other than Unity scripting.
It's totally random and doesn't send it anywhere or store anywhere besides the div random and that's it.
Update: Added Symbols with a probability of 10%
Letters: 50%
Numbers: 40%
Here's the source:
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>RandomIZER</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
(function() {/*
A JavaScript implementation of the SHA family of hashes, as defined in FIPS
PUB 180-2 as well as the corresponding HMAC implementation as defined in
FIPS PUB 198a
Copyright Brian Turek 2008-2012
Distributed under the BSD License
See http://caligatio.github.com/jsSHA/ for more information
Several functions taken from Paul Johnson
*/
function k(a){throw a;}function s(a,e){var b=[],f=(1<<e)-1,c=a.length*e,d;for(d=0;d<c;d+=e)b[d>>>5]|=(a.charCodeAt(d/e)&f)<<32-e-d%32;return{value:b,binLen:c}}function u(a){var e=[],b=a.length,f,c;0!==b%2&&k("String of HEX type must be in byte increments");for(f=0;f<b;f+=2)c=parseInt(a.substr(f,2),16),isNaN(c)&&k("String of HEX type contains invalid characters"),e[f>>>3]|=c<<24-4*(f%8);return{value:e,binLen:4*b}}
function v(a){var e=[],b=0,f,c,d,g,h;-1===a.search(/^[a-zA-Z0-9=+\/]+$/)&&k("Invalid character in base-64 string");f=a.indexOf("=");a=a.replace(/\=/g,"");-1!==f&&f<a.length&&k("Invalid '=' found in base-64 string");for(c=0;c<a.length;c+=4){h=a.substr(c,4);for(d=g=0;d<h.length;d+=1)f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(h[d]),g|=f<<18-6*d;for(d=0;d<h.length-1;d+=1)e[b>>2]|=(g>>>16-8*d&255)<<24-8*(b%4),b+=1}return{value:e,binLen:8*b}}
function w(a,e){var b="",f=4*a.length,c,d;for(c=0;c<f;c+=1)d=a[c>>>2]>>>8*(3-c%4),b+="0123456789abcdef".charAt(d>>>4&15)+"0123456789abcdef".charAt(d&15);return e.outputUpper?b.toUpperCase():b}
function x(a,e){var b="",f=4*a.length,c,d,g;for(c=0;c<f;c+=3){g=(a[c>>>2]>>>8*(3-c%4)&255)<<16|(a[c+1>>>2]>>>8*(3-(c+1)%4)&255)<<8|a[c+2>>>2]>>>8*(3-(c+2)%4)&255;for(d=0;4>d;d+=1)b=8*c+6*d<=32*a.length?b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>>6*(3-d)&63):b+e.b64Pad}return b}
function y(a){var e={outputUpper:!1,b64Pad:"="};try{a.hasOwnProperty("outputUpper")&&(e.outputUpper=a.outputUpper),a.hasOwnProperty("b64Pad")&&(e.b64Pad=a.b64Pad)}catch(b){}"boolean"!==typeof e.outputUpper&&k("Invalid outputUpper formatting option");"string"!==typeof e.b64Pad&&k("Invalid b64Pad formatting option");return e}function z(a,e){var b=(a&65535)+(e&65535);return((a>>>16)+(e>>>16)+(b>>>16)&65535)<<16|b&65535}
function A(a,e,b,f,c){var d=(a&65535)+(e&65535)+(b&65535)+(f&65535)+(c&65535);return((a>>>16)+(e>>>16)+(b>>>16)+(f>>>16)+(c>>>16)+(d>>>16)&65535)<<16|d&65535}
function B(a,e){var b=[],f,c,d,g,h,C,t,j,D,l=[1732584193,4023233417,2562383102,271733878,3285377520],n=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,
1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[e>>>5]|=128<<24-e%32;a[(e+
65>>>9<<4)+15]=e;D=a.length;for(t=0;t<D;t+=16){f=l[0];c=l[1];d=l[2];g=l[3];h=l[4];for(j=0;80>j;j+=1)b[j]=16>j?a[j+t]:(b[j-3]^b[j-8]^b[j-14]^b[j-16])<<1|(b[j-3]^b[j-8]^b[j-14]^b[j-16])>>>31,C=20>j?A(f<<5|f>>>27,c&d^~c&g,h,n[j],b[j]):40>j?A(f<<5|f>>>27,c^d^g,h,n[j],b[j]):60>j?A(f<<5|f>>>27,c&d^c&g^d&g,h,n[j],b[j]):A(f<<5|f>>>27,c^d^g,h,n[j],b[j]),h=g,g=d,d=c<<30|c>>>2,c=f,f=C;l[0]=z(f,l[0]);l[1]=z(c,l[1]);l[2]=z(d,l[2]);l[3]=z(g,l[3]);l[4]=z(h,l[4])}return l}
window.jsSHA=function(a,e,b){var f=null,c=0,d=[0],g=0,h=null,g="undefined"!==typeof b?b:8;8===g||16===g||k("charSize must be 8 or 16");"HEX"===e?(0!==a.length%2&&k("srcString of HEX type must be in byte increments"),h=u(a),c=h.binLen,d=h.value):"ASCII"===e||"TEXT"===e?(h=s(a,g),c=h.binLen,d=h.value):"B64"===e?(h=v(a),c=h.binLen,d=h.value):k("inputFormat must be HEX, TEXT, ASCII, or B64");this.getHash=function(b,a,e){var g=null,h=d.slice(),n="";switch(a){case "HEX":g=w;break;case "B64":g=x;break;default:k("format must be HEX or B64")}"SHA-1"===
b?(null===f&&(f=B(h,c)),n=g(f,y(e))):k("Chosen SHA variant is not supported");return n};this.getHMAC=function(b,a,e,f,h){var n,p,m,E,r,F,G=[],H=[],q=null;switch(f){case "HEX":n=w;break;case "B64":n=x;break;default:k("outputFormat must be HEX or B64")}"SHA-1"===e?(m=64,F=160):k("Chosen SHA variant is not supported");"HEX"===a?(q=u(b),r=q.binLen,p=q.value):"ASCII"===a||"TEXT"===a?(q=s(b,g),r=q.binLen,p=q.value):"B64"===a?(q=v(b),r=q.binLen,p=q.value):k("inputFormat must be HEX, TEXT, ASCII, or B64");
b=8*m;a=m/4-1;m<r/8?("SHA-1"===e?p=B(p,r):k("Unexpected error in HMAC implementation"),p[a]&=4294967040):m>r/8&&(p[a]&=4294967040);for(m=0;m<=a;m+=1)G[m]=p[m]^909522486,H[m]=p[m]^1549556828;"SHA-1"===e?E=B(H.concat(B(G.concat(d),b+c)),b+F):k("Unexpected error in HMAC implementation");return n(E,y(h))}};})();
</script>
<script>
function GenRandom(hash, debug, trim)
{
var um, dois, trez, quatro, cinco, seis, sete, oito, nove, dez, onze, doze, treze, catorze, quinze;
var letters = new Array();
letters[0] = "a";
letters[1] = "b";
letters[2] = "c";
letters[3] = "d";
letters[4] = "e";
letters[5] = "f";
letters[6] = "g";
letters[7] = "h";
letters[8] = "i";
letters[9] = "j";
letters[10] = "k";
letters[11] = "l";
letters[12] = "m";
letters[13] = "n";
letters[14] = "o";
letters[15] = "p";
letters[16] = "q";
letters[17] = "r";
letters[18] = "s";
letters[19] = "t";
letters[20] = "u";
letters[21] = "v";
letters[22] = "w";
letters[23] = "x";
letters[24] = "y";
letters[25] = "z";
var a = Math.floor((Math.random()*100)+1);
var b = Math.floor((Math.random()*100)+1);
var numbers = new Array();
numbers[0] = 0;
numbers[1] = 1;
numbers[2] = 2;
numbers[3] = 3;
numbers[4] = 4;
numbers[5] = 5;
numbers[6] = 6;
numbers[7] = 7;
numbers[8] = 8;
numbers[9] = 9;
var symbols = new Array();
symbols[0] = "*";
symbols[1] = "+";
symbols[2] = "!";
symbols[3] = "%";
symbols[4] = "#";
for(var i = 0; i < 15; i++)
{
var a = Math.floor((Math.random()*100)+1);
if(a < 50) //It's letter
{
var c = Math.floor((Math.random()*100)+1);
if(c < 50) //Lower case
{
var b = letters[Math.floor((Math.random()*26)+0)];
}
else //uppercase
{
var b = letters[Math.floor(Math.random() * 26) + 0];
b = b.toUpperCase();
}
}
else if(a >= 50 && a < 90) //It's number
{
var b = numbers[Math.floor((Math.random()*10)+0)];
}
else
{
var b = symbols[Math.floor((Math.random()*5)+0)];
}
if(i == 0)
{
um = b;
}
else if(i == 1)
{
dois = b;
}
else if(i == 2)
{
trez = b;
}
else if(i == 3)
{
quatro = b;
}
else if(i == 4)
{
cinco = b;
}
else if(i == 5)
{
seis = b;
}
else if(i == 6)
{
sete = b;
}
else if(i == 7)
{
oito = b;
}
else if(i == 8)
{
nove = b;
}
else if(i == 9)
{
dez = b;
}
else if(i == 10)
{
onze = b;
}
else if(i == 11)
{
doze = b;
}
else if(i == 12)
{
treze = b;
}
else if(i == 13)
{
catorze = b;
}
else if(i == 14)
{
quinze = b;
}
}
if(typeof um === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
um = z;
}
else if(typeof dois === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
dois = z;
}
else if(typeof trez === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
trez = z;
}
else if(typeof quatro === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
quatro = z;
}
else if(typeof cinco === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
cinco = z;
}
else if(typeof seis === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
seis = z;
}
else if(typeof sete === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
sete = z;
}
else if(typeof oito === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
oito = z;
}
else if(typeof nove === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
nove = z;
}
else if(typeof dez === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
dez = z;
}
else if(typeof onze === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
onze = z;
}
else if(typeof doze === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
doze = z;
}
else if(typeof treze === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
treze = z;
}
else if(typeof catorze === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
catorze = z;
}
else if(typeof quinze === 'undefined')
{
var z = symbols[Math.floor(Math.random() * 5) + 0];
quinze = z;
}
if(debug)
var random1 = um + "." + dois + "." + trez + "." + quatro + "." + cinco + "." + seis + "." + sete + "." + oito + "." + nove + "." + dez + "." + onze + "." + doze + "." + treze + "." + catorze + "." + quinze;
else
var random1 = um + dois +trez +quatro+ cinco +seis +sete +oito + nove + dez + onze + doze + treze + catorze + quinze;
if(hash)
{
var shaObj = new jsSHA(random1, "TEXT");
var hash = shaObj.getHash("SHA-1", "HEX");
var hmac = shaObj.getHMAC("SecretKey", "TEXT", "SHA-1", "HEX");
random1 = hash;
if(trim)
{
var trimmedString = random1.substring(0, 15);
random1 = trimmedString;
}
}
document.getElementById("random").innerHTML = random1;
}
</script>
</head>
<body>
<h1>RandomIZER</h1>
<br>
<p>Please choose one of the following random:</p>
<p><a href="#" onclick="GenRandom(false, false, false)">Random 1</a></p>
<p><a href="#" onclick="GenRandom(true, false, false)">Random 2</a></p>
<p><a href="#" onclick="GenRandom(true, false, true)">Random 3</a></p>
<div id="random">
</div>
</body>
</html>
I've used a javascript lib for the hashing in case some people prefer hashed its a little more random then the others. And as for the normal randoming it's all my work, a bit newby but it creates some cool passwords.
btw
var um, dois, trez, quatro, cinco, seis, sete, oito, nove, dez, onze, doze, treze, catorze, quinze;
this means one, two, three, till fifteen in my language so go ahead and feel free to pass it to english or something if you want.
Here's a demo in my website: http://www.oryzhon.com/random
Just sharing with you guys so feel free to use it if you want.. I didn't felt like adding symbols but i should i know. This was just to code something in javascript other than Unity scripting.