SysWorkSoft.net!HomeProductsSupportDownload
Contacts
Links
System & network administration  

Random password generator with Javascript

A simple script to create random passwords. I'm sure the most difficult will be to remember the password!

Generated password

 

Only use numbers and letters (easy to remember)?

Yes No

Only use lower case letters (more easier to remember)?

Yes No


Here's the code:

<script language="JavaScript">
var today=new Date();
var jran=today.getTime();

function random() {
	ia=9301;
	ic=49297;
	im=233280;
	jran = (jran*ia+ic) % im;
	return jran/(im*1.0);
};

function rand(number) {
	return Math.ceil(random()*number);
};

function makearray(n) {
	this.length = n;
	for (var i = 1; i <= n; i++) this[i] = 0;
	return this;
}

var asciitable = new makearray (128);
asciitable.length=128;
for (var i=0;i<=127;i++) asciitable[i]="";
asciitable[33]="!"; asciitable[34]="\""; 
asciitable[35]="#"; asciitable[36]="$";
asciitable[37]="%"; asciitable[38]="&"; 
asciitable[39]="'"; asciitable[40]="(";
asciitable[41]=")"; asciitable[42]="*"; 
asciitable[43]="+"; asciitable[44]=",";
asciitable[45]="-"; asciitable[46]="."; 
asciitable[47]="/"; asciitable[48]="0";
asciitable[49]="1"; asciitable[50]="2"; 
asciitable[51]="3"; asciitable[52]="4";
asciitable[53]="5"; asciitable[54]="6"; 
asciitable[55]="7"; asciitable[56]="8";
asciitable[57]="9"; asciitable[58]=":"; 
asciitable[59]=";"; asciitable[60]="<";
asciitable[61]="="; asciitable[62]=">"; 
asciitable[63]="?"; asciitable[64]="@";
asciitable[65]="A"; asciitable[66]="B"; 
asciitable[67]="C"; asciitable[68]="D";
asciitable[69]="E"; asciitable[70]="F"; 
asciitable[71]="G"; asciitable[72]="H";
asciitable[73]="I"; asciitable[74]="J"; 
asciitable[75]="K"; asciitable[76]="L";
asciitable[77]="M"; asciitable[78]="N"; 
asciitable[79]="O"; asciitable[80]="P";
asciitable[81]="Q"; asciitable[82]="R"; 
asciitable[83]="S"; asciitable[84]="T";
asciitable[85]="U"; asciitable[86]="V"; 
asciitable[87]="W"; asciitable[88]="X";
asciitable[89]="Y"; asciitable[90]="Z"; 
asciitable[91]="["; asciitable[92]="\\";
asciitable[93]="]"; asciitable[94]="^"; 
asciitable[95]="_"; asciitable[96]="`";
asciitable[97]="a"; asciitable[98]="b"; 
asciitable[99]="c"; asciitable[100]="d";
asciitable[101]="e"; asciitable[102]="f"; 
asciitable[103]="g"; asciitable[104]="h";
asciitable[105]="i"; asciitable[106]="j"; 
asciitable[107]="k"; asciitable[108]="l";
asciitable[109]="m"; asciitable[110]="n"; 
asciitable[111]="o"; asciitable[112]="p";
asciitable[113]="q"; asciitable[114]="r"; 
asciitable[115]="s"; asciitable[116]="t";
asciitable[117]="u"; asciitable[118]="v"; 
asciitable[119]="w"; asciitable[120]="x";
asciitable[121]="y"; asciitable[122]="z"; 
asciitable[123]="{"; asciitable[124]="|";
asciitable[125]="}"; asciitable[126]="~";

function nchar(num) {
	if ((num>=33) && (num<=127)) return asciitable[num];
}

function doit() {
	var i;
	var n;
	var s = "";
	if (document.gen.simple[0].checked==false) {
		for (i=1;i<=8;i++) {
			n=0;
			while (n<=32) n = rand(126);
			s = s + nchar(n);
		}
	}
	else {
		if (document.gen.psimple[0].checked==true) {
			for (i=1;i<=8;i++) {
				n=0;
				while ( (n<=47) || 
                                        ((n>=58) && (n<=96)) || 
                                        (n>=123))  n = rand(126);
				s = s + nchar(n);
			}
		}
		else {
			for (i=1;i<=8;i++) {
				n=0;
				while ( (n<=47) || 
                                        ((n>=58) && (n<=64)) || 
                                        (n>=123) || 
                                        ((n>=91) && (n<=96)))  
                                        n = rand(126);
				s = s + nchar(n);
			}
		}
	}
	document.gen.result.value = s;
}
</script>

You can just cut and paste this code into your web page.

© 1998-2006 SysWorkSoft.net