码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 的随机密码生成 .

时间:2014-10-25 17:10:44      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   log   

$.extend({ 
  password: function (length, special) {
    var iteration = 0;
    var password = "";
    var randomNumber;
    if(special == undefined){
        var special = false;
    }
    while(iteration < length){
        randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
        if(!special){
            if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
            if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
            if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
            if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
        }
        iteration++;
        password += String.fromCharCode(randomNumber);
    }
    return password;
  }
});

// How to use
$.password(8);
$.password(12, true);

 

jQuery 的随机密码生成 .

标签:style   blog   color   io   ar   sp   div   on   log   

原文地址:http://www.cnblogs.com/vinsonLu/p/4050300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!