js随机密码产生函数_javascript技巧
来源:动视网
责编:小采
时间:2020-11-27 20:54:30
js随机密码产生函数_javascript技巧
js随机密码产生函数_javascript技巧: 代码如下: function randPassword() { var text=['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+;./<>']; var rand = function(min, max){return
导读js随机密码产生函数_javascript技巧: 代码如下: function randPassword() { var text=['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+;./<>']; var rand = function(min, max){return

代码如下:
function randPassword()
{
var text=['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+";",./?<>'];
var rand = function(min, max){return Math.floor(Math.max(min, Math.random() * (max+1)));}
var len = rand(8, 16); // 长度为8-16
var pw = '';
for(i=0; i
{
var strpos = rand(0, 3);
pw += text[strpos].charAt(rand(0, text[strpos].length));
}
return pw;
}
测试代码:
js随机密码产生函数_javascript技巧
js随机密码产生函数_javascript技巧: 代码如下: function randPassword() { var text=['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+;./<>']; var rand = function(min, max){return