測試密碼強度,密碼強度

來源:互聯網
上載者:User

測試密碼強度,密碼強度


<html>

<!--激情在最後面,請看最後面紅色字


 這是是個計算密碼強度的執行個體

                網上有很多這樣的例子

               不過呢,都不怎麼好

                這是我寫的一個完整的效果,可以通用,

                new一下就可以執行個體化一個【關注重點】,

                主要是用物件導向來寫,感覺知道做下筆記

              密碼強度驗證規則如下:




-->

 <meta charset="UTF-8">
    <title>計算密碼強度</title>
  <head></head>
  <style>
   span{
    display: inline-block;
    line-height: 20px;
    text-align: center;
    width:20px;
    height:20px;
    border-radius: 50%;
    background:#ccc;
    font-size: 12px;
    color:#fff;
   }
   .current{
    background:green;
    color:#000;
   }
  </style>
<script src="jquery.js"></script>
  <body>
    <input type="text" id="test" class="input1">
    <input type="submit" value="submit" id="submit"/>
    <div class="vaild">
    <span>弱</span>
    <span>中</span>
    <span>強</span>
    </div>


     <input type="text" id="test" class="input2">
      <input type="submit" value="submit" id="submit"/>
    <div class="vaild2">
   <span>弱</span>
   <span>中</span>
   <span>強</span>
    </div>
    <script>
    //建構函式
    function Vaild(){
        this.input=$(".input1"),
    this.show=$(".vaild span"),
    this.name="current",
    this.vailded=function()
    {
    var _this=this;
    this.input.on("keyup", function()
    {
    // var div=$("#fen");
     //var tips=$("#tips");
     var f=0;//每次都清空
     var vals=$(this).val();
     //數組
     var num;
     var en;
     var fh;
     var jl;
     //得分
      var lenF;
     var numF;
     var enF;
     var fhF;
     var jlF;
     //判斷長度
     if(vals.length>0&&vals.length <=4){
         lenF=5;
     }
     else if(vals.length>4&&vals.length<=7){
         lenF=10;
     }
     else if(vals.length>=8){
       lenF=25;
     }
     //判斷數字
    num=vals.match(/\d/g)?vals.match(/\d/g):0;
    if(num==0){
     numF=0;
    }
    else if(num.length==1){
     numF=10;
    }
    else if(num.length>=2){
     numF=20;
    }
    //判斷字母長度
     en=vals.match(/[A-Za-z_]/g)?vals.match(/[A-Za-z_]/g):0;
    if(en==0){
     enF=0;
    }
    else if(en.length==1){
     enF=10;
    }
    else if(en.length>=2){
     enF=20;
    }
   //匹配符號
    fh=vals.match(/\W/g)?vals.match(/\W/g):0;
    if(fh==0){
     fhF=0;
    }
    else if(fh.length==1){
     fhF=10;
    }
    else if(fh.length>=2){
     fhF=25;
    }
    //獎勵
    if(/\d+/g.test(vals)&&/[a-z_]+/g.test(vals)){
     jlF=2;
    }
    if(/\d+/g.test(vals)&&/[a-z_]+/g.test(vals)&&/\W+/g.test(vals)){
     jlF=3;
    }
    if(/\d+/g.test(vals)&&/[A-Z]+/g.test(vals)&&/[a-z_]+/g&&/\W+/g.test(vals)){
     jlF=5;
    }
    if(jlF==undefined||jlF=="NaN"||jlF=="undefined")
    {
     jlF=0;
    }
    var count=Number(lenF)+Number(numF)+Number(enF)+Number(fhF)+Number(jlF);
    //切換“弱” “中” “強”
     if(count>=0&&count<60){
       _this.show.eq(0).addClass(_this.name).siblings().removeClass(_this.name);
     }
     else if(count<90&&count>=60){
            _this.show.eq(2).removeClass(_this.name).siblings().addClass(_this.name);
     }
     else if(count>90){
        _this.show.addClass(_this.name);
     }
     else{
      _this.show.removeClass(_this.name);
     }
     //顯示分數
    // div.html("分數 : "+ count)
     //測試多對應的所得分數
     console.log("長度分數:"+lenF)
     console.log("數字分數:"+numF)
     console.log("字母分數: "+enF)
     console.log("符號分數: "+fhF)
     console.log("獎勵分數: "+jlF)
   })


    }

    };

///執行個體化建構函式

    var dd=new Vaild();
    dd.vailded();
   
   //開啟第二個
   var bb=new Vaild();
   bb.input=$(".input2");
   bb.show=$(".vaild2 span");
   bb.vailded();
  
    </script>
  </body>
</html>

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.