首页 > 其他 > 详细

对输入密码的一个加密规则和方式的编写

时间:2019-12-22 21:18:22      阅读:98      评论:0      收藏:0      [点我收藏+]

getPwd () {
      this.form.pwd = this.randomPassword(8)
    },
    randomPassword(length) {
      length = Number(length)
      // Limit length
      if (length < 8) {
        length = 8
      } else if (length > 16) {
        length = 16
      }
      let passwordArray = [‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘, ‘abcdefghijklmnopqrstuvwxyz‘, ‘1234567890‘, ‘@#$%&‘];
      var password = [];
      let n = 0;
      for (let i = 0; i < length; i++) {
        // If password length less than 9, all value random
        if ( password.length < (length - 4) ) {
          // Get random passwordArray index
          let arrayRandom = Math.floor(Math.random() * 4);
          // Get password array value
          let passwordItem = passwordArray[arrayRandom];
          // Get password array value random index
          // Get random real value
          let item = passwordItem[Math.floor(Math.random() * passwordItem.length)];
          password.push(item);
        } else {
          // If password large then 9, lastest 4 password will push in according to the random password index
          // Get the array values sequentially
          let newItem = passwordArray[n];
          let lastItem = newItem[Math.floor(Math.random() * newItem.length)];
          // Get array splice index
          let spliceIndex = Math.floor(Math.random() * password.length);
          password.splice(spliceIndex, 0, lastItem);
          n++
        }
      }
      return password.join("");
    }

对输入密码的一个加密规则和方式的编写

原文:https://www.cnblogs.com/robot666/p/12080914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!