Jest to poręczny mały skrypt, który generuje hasła. Pozwala ustawić liczbę znaków, które chcesz dla swojego hasła i czy znaki interpunkcyjne są dozwolone.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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; } |
Tutaj przykład zastosowania tego skryptu:
JavaScript: Generator haseł (Password Generator)