«

»

Jun 08

Print this Post

Client Side JavaScript Key Generator (keygen.htm)

Client side JavaScript random key generator. Allows the user to select whether all ascii characters are allowed(many are not acceptible for passwords in most systems), only common characters (these will usually be accepted for passwords), or no symbols (uses upper and lower case letters and numbers only).

Keygen
Keygen
keygen.zip
971.0 B
34 Downloads
Details
<html><head>
<script language="javascript">
  function makeKey(keySize,keySymbols)
  	{
    document.frmKeygen.btnGenerate.value="Generating Key...";
    var i = 0;
    var tkey = new String("");
    var intAscii = 0;
    var intSize = 0;
    var intSymbols = 0;
    intSize = Math.floor(keySize);
    intSymbols = Math.floor(keySymbols);
    do{
    	intAscii = Math.floor(Math.random()*256);
      if(intSymbols==0){
      	if((intAscii >= 48 && intAscii <=57)||(intAscii >= 65 && intAscii <=90)||(intAscii >= 97 && intAscii <=122)){ 
					tkey = tkey + String.fromCharCode(intAscii);
          }
				else i = i - 1;
      	}
      else if(intSymbols==1){
      	if (intAscii >= 33 && intAscii <=122){
					tkey = tkey + String.fromCharCode(intAscii);
          }
				else i = i - 1;
      	}
      else if(intSymbols==2){
      	tkey = tkey + String.fromCharCode(intAscii);
      	}
      i += 1;
      }
    while(tkey.length<intSize);
    document.frmKeygen.txtOut.value = tkey;
    document.frmKeygen.btnGenerate.value="Generate Key";
    }
</script>

</head>
<body>
	<form name="frmKeygen">
		<table border="1" bordercolor="black" cellspacing="0" cellpadding="5">
			<tr>
      	<td colspan="2" align="center">
        	Select Key Length
          <select name="size">
          	<option value=2>2
          	<option value=4>4
          	<option value=8>8
          	<option value=16>16
          	<option value=32>32
          	<option value=64>64
          	<option value=128>128
          	<option value=256>256
          	<option value=512>512
          	<option value=1024>1K
          	<option value=2048>2K
          	<option value=4096>4K
          	<option value=8192>8K
          	<option value=16384>16K
          	<option value=32768>32K
          </select>
        </td>
      </tr>
			<tr>
				<td width="50%" align="center">Include Symbols?</td>
				<td width="50%" align="center">
					<select name="symbols">
						<option value=0>None
						<option value=1>Common
						<option value=2>All
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="button" name="btnGenerate" value="Generate Key" onClick="makeKey(document.frmKeygen.size.value,document.frmKeygen.symbols.value);">
				</td>
			</tr>
		</table>
		
		Key:<br>
    <textarea name="txtOut" cols="80" rows="20" wrap="hard"></textarea>
	</form>
</body>
</html>

Permanent link to this article: https://www.wperry.net/code/keygen-htm/

Leave a Reply

Your email address will not be published. Required fields are marked *