Password Generator

Generated Password:

# of chars

No Punctuation Marks
Random Length (6 - 12)

 
 


This is a little script which can generate a random password. Test it out by clicking generate random password.

Javascript

<script language="JavaScript">

function GeneratePassword() {
    
    if (parseInt(navigator.appVersion) <= 3) { 
        alert("Sorry this only works in 4.0 browsers"); 
        return true; 
    }
    
    var length=8;
    var sPassword = "";
    length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;
    
    var noPunction = (document.aForm.punc.checked);
    var randomLength = (document.aForm.rLen.checked);
    
    if (randomLength) { 
        length = Math.random(); 
        
        length = parseInt(length * 100);
        length = (length % 7) + 6
    }
    
    
    for (i=0; i < length; i++) {
    
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        
        sPassword = sPassword + String.fromCharCode(numI);
    }
    
    document.aForm.passField.value = sPassword
    
    return true;
}

function getRandomNum() {
        
    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000    
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127        
    rndNum = (rndNum % 94) + 33;
            
    return rndNum;
}

function checkPunc(num) {
    
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }    
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    
    return false;
}

</script>

HTML

<form name="aForm">
		<table>
			<tr>
				<td>Generated Password:<br>
			    <input type="text" name="passField" value="" size="15"><BR>
				</td>
			    <td>
					# of chars<br>
						<select name="charLen">
						<option value="4">4
						<option value="5">5
						<option value="6">6
						<option value="7">7
						<option value="8" selected>8
						<option value="9">9
						<option value="10">10
						<option value="11">11
						<option value="12">12
						<option value="13">13
						<option value="14">14
						<option value="15">15    
						</select>
				</td>	
			</tr>    
			<tr>
				<td>
					<p>
					    <input type="checkbox" name="punc" checked> No Punctuation Marks <BR>
					    <input type="checkbox" name="rLen"> Random Length (6 - 12) <BR>
				    </p>
				</td>
			    <td>&nbsp;</td>
		    </tr>
			<tr>
				<td colspan="2" align=center>&nbsp;</td>
			</tr>    
		    <tr>
				<td colspan="2" align=center>    
					<p>
						<input type="button" value=" Generate Password " onClick="GeneratePassword()">
					</p>
				</td>
			</tr>
		</table>


javaScript passwords generator password generator


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site