

11/5
2015
今天要把许多网站的密码重新设置,所以自己写了个密码生成器。比较简陋,不过在简单的用途上应该算够用了。
您希望密码中包含哪些内容?
阿拉伯数字(0-9)
大写英文字母(A-Z)
小写英文字母(a-z)
特殊符号(键盘上除了\的所有输入符号)
请设置密码位数:
生成结果:
代码如下:
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 | < p >您希望密码中包含哪些内容?</ p > < input type = "checkbox" name = "pwType" value = "Number" > 阿拉伯数字(0-9)< br > < input type = "checkbox" name = "pwType" value = "Upper" > 大写英文字母(A-Z)< br > < input type = "checkbox" name = "pwType" value = "Lower" > 小写英文字母(a-z)< br > < input type = "checkbox" name = "pwType" value = "Punctuation" > 特殊符号(键盘上除了\的所有输入符号)< br >< br > 请设置密码位数:< input type = "text" name = "pwLength" value = "10" >< br >< br > 生成结果:< input type = "text" name = "outputPw" />< br >< br > < button name = "createPwButton" >生成密码</ button > < script type = "text/javascript" > function createPW () { var allPw={ "Number":"0123456789", "Upper":"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "Lower":"abcdefghijklmnopqrstuvwxyz", "Punctuation":"~!@#$%^&*()_+[]{}|`;:,./?><-=" } var allowPw=""; for (var i = 0; i < document.getElementsByName ("pwType").length; i++) { if (document.getElementsByName("pwType")[i].checked) { allowPw+=allPw[document.getElementsByName("pwType")[i].value]; }; }; var pwLength = parseInt (document.getElementsByName("pwLength")[0].value,10); var pwResult = "" ; for (var i = 0 ; i < pwLength; i++) { var nowRandom = parseInt (Math.random()*allowPw.length,10); pwResult+=allowPw.substring(nowRandom, nowRandom+1); }; document.getElementsByName("outputPw")[0] .value = pwResult ; } document.getElementsByName("createPwButton")[0] .onclick = function () { createPW(); } </script> |
使用js随机生成密码
-
Google Chrome 64
Mac OS X 10.13.3
-
Google Chrome 42
Windows 7 x64 Edition
点击生成密码 卡了 啊啊啊。
-
Safari 6
iPod iOS 6.1.3
Lastpass大法好
hello Saber, parseInt和substring 是什么意思,它们主要的作用是什么,我不是很明白,我刚开始学js , 很感激如果可以回复!!~O(∩_∩)O~