800M

20 object(s)
 

密码生成之随机字符串

在开发过程中,常常需要设置密码,如数据库密码、网盘密码、网站密码等等。由于密码只是临时用一下,有时候还会跟其他开发人员交流信息,为了避免泄露自己的个人密码相关信息,使用随机密码往往是个不错的选择。

1function generate(){
2 var i, n, s = "";
3 n = Math.floor(Math.random()*8) + 11;//生成11-18位密码
4 for(i=1; i<=n; i++){
5 r = Math.floor(Math.random()*4);
6 if(r == 1) s = s + String.fromCharCode(65 + Math.floor(Math.random()*26));//大写字母
7 else if(r == 2) s = s + String.fromCharCode(97 + Math.floor(Math.random()*26));//小写字母
8 else s = s + String.fromCharCode(48 + Math.floor(Math.random()*10));//数字
9 }
10 return s;
11}