|
@@ -181,106 +181,6 @@ export function findarrays (ar, feature, v) {
|
|
|
return arr
|
|
|
}
|
|
|
|
|
|
-// 随机长度
|
|
|
-function randomNum (start, end) {
|
|
|
- return Math.floor(Math.random() * (Number(end) - Number(start)) + start)
|
|
|
-}
|
|
|
-
|
|
|
-// 字母随机
|
|
|
-function randomAlp (arr, count) {
|
|
|
- let shuffled = arr.slice(0),
|
|
|
- i = arr.length,
|
|
|
- min = i - count,
|
|
|
- temp,
|
|
|
- index
|
|
|
- while (i-- > min) {
|
|
|
- index = Math.floor((i + 1) * Math.random())
|
|
|
- temp = shuffled[index]
|
|
|
- shuffled[index] = shuffled[i]
|
|
|
- shuffled[i] = temp
|
|
|
- }
|
|
|
- return shuffled.slice(min)
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @param {minLen} 密码最小长度
|
|
|
- * @param {maxLen} 密码最大长度
|
|
|
- * @param {struc} 密码规则
|
|
|
- * @returns {Object}
|
|
|
- * 4位密码规则 1111 = 大写 小写 特殊字符 数字 都开启
|
|
|
- */
|
|
|
-export function pwdProduce (minLen, maxLen, struc) {
|
|
|
- // 密码规则转化
|
|
|
- const pwdStruc = typeof struc === 'string' ? struc.split('') : `${struc}`.split('')
|
|
|
- // 字母
|
|
|
- const alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
|
|
- // 特殊字符
|
|
|
- const special = ['~', '!', '@', '#', '$', '%', '^', '&', '*', '_', '+', '.']
|
|
|
- // 数字
|
|
|
- const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
|
|
- // 密码随机长度
|
|
|
- const pwdLen = randomNum(minLen, maxLen)
|
|
|
- const datas = []
|
|
|
-
|
|
|
- if (pwdStruc.length) {
|
|
|
- let typeLong = Number(pwdStruc[0]) + Number(pwdStruc[1]) + Number(pwdStruc[2]) + Number(pwdStruc[3])
|
|
|
- let passLong = Math.ceil(pwdLen / typeLong)
|
|
|
- let dis = ''
|
|
|
- if (pwdStruc[0] == 1) {
|
|
|
- let arr = alphabet.toLocaleUpperCase().split('')
|
|
|
- let v = randomAlp(arr, passLong)
|
|
|
- for (let i = 0; i < passLong; i++) {
|
|
|
- dis += v[i]
|
|
|
- }
|
|
|
- }
|
|
|
- if (pwdStruc[1] == 1) {
|
|
|
- let arr = alphabet.split('')
|
|
|
- let v = randomAlp(arr, passLong)
|
|
|
- for (let i = 0; i < passLong; i++) {
|
|
|
- dis += v[i]
|
|
|
- }
|
|
|
- }
|
|
|
- if (pwdStruc[2] == 1) {
|
|
|
- let arr = special
|
|
|
- let v = randomAlp(arr, passLong)
|
|
|
- for (let i = 0; i < passLong; i++) {
|
|
|
- dis += v[i]
|
|
|
- }
|
|
|
- }
|
|
|
- if (pwdStruc[3] == 1) {
|
|
|
- let arr = numbers
|
|
|
- let v = randomAlp(arr, passLong)
|
|
|
- for (let i = 0; i < passLong; i++) {
|
|
|
- dis += v[i]
|
|
|
- }
|
|
|
- }
|
|
|
- return dis
|
|
|
- // 缓存当前的密码规则
|
|
|
- // pwdStruc.forEach((item, index) => {
|
|
|
- // if (item == 1) {
|
|
|
- // datas.push(index)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // // 只有一种规则时
|
|
|
- // if (datas.length === 1) {
|
|
|
- // const num = datas[0]
|
|
|
- // const dis = randomAlp(alphabet.split('')).splice(0, pwdLen).join('')
|
|
|
- // switch (num) {
|
|
|
- // case 0:
|
|
|
- // return dis.toLocaleUpperCase()
|
|
|
- // break;
|
|
|
- // case 1:
|
|
|
- // return dis
|
|
|
- // break;
|
|
|
- // default:
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- } else {
|
|
|
- return new Error('密码规则转换失败')
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// 表单输入长度验证
|
|
|
function getRealLength (string) {
|
|
|
let realLength = 0,
|