用js在前台及后台生成随机字符串

用js在前台生成随机字符串





随机密码生成器 - 随机字符串生成器 - Random Password Generator | C7TOOL










 
























用js在后台生成随机字符串


<%@ LANGUAGE='JAVASCRIPT' %>
<%
function rand(max) {
    return Math.floor(Math.random() * max);
};


function getRand(includeNumber,includeLowercaseletters,includeUppercaseletters,includePunctuation,passwordUnique,passwordQuantity,passwordLength)
{
    var chars = "";


    if (includeNumber) chars += "0123456789";
    if (includeLowercaseletters) chars += "abcdefghijklmnopqrstuvwxyz";
    if (includeUppercaseletters) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if (includePunctuation) chars += "`~!@#$%^&*()-_=+[{]}\|;:'\",<.>/?";


    var passwords = [] ;
    for (var i = 0, l = passwordQuantity; i < l; i++) {
        var _chars = chars.split(""),
password = "";
        for (var j = 0, k = passwordLength; j < k; j++) {
            if (_chars.length < 1) break;
            var index = rand(_chars.length);
            password += _chars[index];
            if (passwordUnique) _chars.splice(index, 1);
        };
        passwords.push(password);
    };
    return passwords.join("
");
}


Response.Write(getRand(1,1,1,1,1,8,12));
%>



你可能感兴趣的:(javascript)