首页 > 科学 > 释疑解惑

nodejs 加密算法 JavaScriptNodeJS生成随机码

时间:2023-05-19来源:网络作者:小千
简介:JavaScriptNodeJS生成随机码生成随机码及密码函数及代码/***数字字符串*@param{*}length*@returns*/functionrandomWord1(length){//指定长

【菜科解读】

/** * 数字字符串 * @param {*} length * @returns */ function randomWord1(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = ''; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 大写字母 数字字符串 * * @param {} length * @returns */ function randomWord2(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 小写字母 数字字符串 * * @param {} length * @returns */ function randomWord3(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = 'abcdefghijklmnopqrstuvwxyz'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord4(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 常用特殊字符 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord5(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //指定特殊字符 const specials = "~@#$%^&*()/.,"; let total = numbers letters specials; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 特殊字符 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord6(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //指定特殊字符 const specials = "!#$%&'()* ,-./:;<=>?@[\]^_`{|}~"; let total = numbers letters specials; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } // 数字【04970152848】 console.log("randomWord1 = ", randomWord1(11)); // 数字 大写字母【CE6532REAT7】 console.log("randomWord2 = ", randomWord2(11)); // 数字 小写字母【6a23t040nhu】 console.log("randomWord3 = ", randomWord3(11)); // 数字 大小写字母【0AC9U0t2CsI】 console.log("randomWord4 = ", randomWord4(11)); // 常用特殊字母 数字 大小写字母【hpj4~Catjb4】 console.log("randomWord5 = ", randomWord5(32)); // 特殊字母 数字 大小写字母【5Ra%x]N^8H】 console.log("randomWord6 = ", randomWord6(11));,我来为大家讲解一下关于nodejs 加密算法?跟着小编一起来看一看吧!

nodejs 加密算法(JavaScriptNodeJS生成随机码)

nodejs 加密算法

生成随机码及密码 函数及代码

/** * 数字字符串 * @param {*} length * @returns */ function randomWord1(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = ''; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 大写字母 数字字符串 * * @param {} length * @returns */ function randomWord2(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 小写字母 数字字符串 * * @param {} length * @returns */ function randomWord3(length) { //指定长度: 默认长度8位 length || (length = 8); const numbers = '0123456789'; const letters = 'abcdefghijklmnopqrstuvwxyz'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord4(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; let total = numbers letters; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 常用特殊字符 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord5(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //指定特殊字符 const specials = "~!@#$%^&*()/.,"; let total = numbers letters specials; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } /** * 特殊字符 大小写字母 数字字符串 * * @param {*} length * @returns */ function randomWord6(length) { //指定长度: 默认长度8位 length || (length = 8); //指定数字范围, const numbers = '0123456789'; //指定字母范围,(也可以指定字符或者小写字母) const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //指定特殊字符 const specials = "!#$%&'()* ,-./:;<=>?@[\]^_`{|}~"; let total = numbers letters specials; let result = ''; while (length > 0) { length--; result = total[Math.floor(Math.random() * total.length)]; } return result; } // 数字【04970152848】 console.log("randomWord1 = ", randomWord1(11)); // 数字 大写字母【CE6532REAT7】 console.log("randomWord2 = ", randomWord2(11)); // 数字 小写字母【6a23t040nhu】 console.log("randomWord3 = ", randomWord3(11)); // 数字 大小写字母【0AC9U0t2CsI】 console.log("randomWord4 = ", randomWord4(11)); // 常用特殊字母 数字 大小写字母【hpj4~Catjb4】 console.log("randomWord5 = ", randomWord5(32)); // 特殊字母 数字 大小写字母【5Ra%x]N^8H】 console.log("randomWord6 = ", randomWord6(11));

声明:本文内容仅代表作者个人观点,与本站立场无关。

如有内容侵犯您的合法权益,请及时与我们联系,我们将第一时间安排处理