最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于JQuery的密碼強度驗證代碼

 更新時間:2010年03月01日 21:59:18   作者:  
密碼強度驗證的方式有很多,今天給大家推薦一個通過JQuery實現的密碼強度驗證控件,只需要很少的代碼便能實現。

   


因為是基于JQuery的控件,當然需要JQuery庫,還要一個本控件的JS。JQuery的JS大家可以到官網下載:http://code.jquery.com/jquery-1.4.2.min.js
這個控件的JS文件:password_strength_plugin.js
password_strength_plugin.js

復制代碼 代碼如下:

(function($){
$.fn.shortPass = 'Too short';
$.fn.badPass = 'Weak';
$.fn.goodPass = 'Good';
$.fn.strongPass = 'Strong';
$.fn.samePassword = 'Username and Password identical.';
$.fn.resultStyle = "";
$.fn.passStrength = function(options) {
var defaults = {
shortPass: "shortPass", //optional
badPass: "badPass", //optional
goodPass: "goodPass", //optional
strongPass: "strongPass", //optional
baseStyle: "testresult", //optional
userid: "", //required override
messageloc: 1 //before == 0 or after == 1
};
var opts = $.extend(defaults, options);
return this.each(function() {
var obj = $(this);
$(obj).unbind().keyup(function()
{
var results = $.fn.teststrength($(this).val(),$(opts.userid).val(),opts);
if(opts.messageloc === 1)
{
$(this).next("." + opts.baseStyle).remove();
$(this).after("<span class=\""+opts.baseStyle+"\"><span></span></span>");
$(this).next("." + opts.baseStyle).addClass($(this).resultStyle).find("span").text(results);
}
else
{
$(this).prev("." + opts.baseStyle).remove();
$(this).before("<span class=\""+opts.baseStyle+"\"><span></span></span>");
$(this).prev("." + opts.baseStyle).addClass($(this).resultStyle).find("span").text(results);
}
});
//FUNCTIONS
$.fn.teststrength = function(password,username,option){
var score = 0;
//password < 4
if (password.length < 4 ) { this.resultStyle = option.shortPass;return $(this).shortPass; }
//password == user name
if (password.toLowerCase()==username.toLowerCase()){this.resultStyle = option.badPass;return $(this).samePassword;}
//password length
score += password.length * 4;
score += ( $.fn.checkRepetition(1,password).length - password.length ) * 1;
score += ( $.fn.checkRepetition(2,password).length - password.length ) * 1;
score += ( $.fn.checkRepetition(3,password).length - password.length ) * 1;
score += ( $.fn.checkRepetition(4,password).length - password.length ) * 1;
//password has 3 numbers
if (password.match(/(.*[0-9].*[0-9].*[0-9])/)){ score += 5;}
//password has 2 symbols
if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){ score += 5 ;}
//password has Upper and Lower chars
if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){ score += 10;}
//password has number and chars
if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)){ score += 15;}
//
//password has number and symbol
if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)){ score += 15;}
//password has char and symbol
if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)){score += 15;}
//password is just a numbers or chars
if (password.match(/^\w+$/) || password.match(/^\d+$/) ){ score -= 10;}
//verifying 0 < score < 100
if ( score < 0 ){score = 0;}
if ( score > 100 ){ score = 100;}
if (score < 34 ){ this.resultStyle = option.badPass; return $(this).badPass;}
if (score < 68 ){ this.resultStyle = option.goodPass;return $(this).goodPass;}
this.resultStyle= option.strongPass;
return $(this).strongPass;
};
});
};
})(jQuery);
$.fn.checkRepetition = function(pLen,str) {
var res = "";
for (var i=0; i<str.length ; i++ )
{
var repeated=true;
for (var j=0;j < pLen && (j+i+pLen) < str.length;j++){
repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen));
}
if (j<pLen){repeated=false;}
if (repeated) {
i+=pLen-1;
repeated=false;
}
else {
res+=str.charAt(i);
}
}
return res;
};

這個控件的css文件:
style.css
復制代碼 代碼如下:

td label{
font-size:14px;
font-weight:bold;
color:#666;
font-family: arail,helvetica,san-serif;
}
input{
height:28px;
width:200px;
border:1px solid #ccc;
font-size:16px;
font-weight: bold;
color:#666;
padding:7px 0 0 4px;
}
/* ADVANCED STYLES */
.top_testresult{
font-weight: bold;
font-size:13px;
font-family: arail,helvetica,san-serif;
color:#666;
padding:0;
margin:0 0 2px 0;
}
.top_testresult span{
padding:6px ;
margin:0;
}
.top_shortPass{
background:#edabab;
border:1px solid #bc0000;
display:block;
}
.top_shortPass span{
}
.top_badPass{
background:#edabab;
border:1px solid #bc0000;
display:block;
}
.top_badPass span{
}
.top_goodPass{
background:#ede3ab;
border:1px solid #bc9f00;
display:block;
}
.top_goodPass span{
}
.top_strongPass{
background:#d3edab;
border:1px solid #73bc00;
display:block;
}
.top_strongPass span{
}
/* RESULT STYLE */
.testresult{
font-weight: bold;
font-size:13px;
font-family: arial,helvetica,san-serif;
color:#666;
padding:0px 0px 12px 10px;
margin-left:10px;
display: block;
height:28px;
float:left;
}
.testresult span{
padding:10px 20px 12px 10px;
margin: 0px 0px 0px 20px;
display:block;
float:right;
white-space: nowrap;
}
.shortPass{
background:url(../images/red.png) no-repeat 0 0;
}
.shortPass span{
background:url(../images/red.png) no-repeat top right;
}
.badPass{
background:url(../images/red.png) no-repeat 0 0;
}
.badPass span{
background:url(../images/red.png) no-repeat top right;
}
.goodPass{
background:url(../images/yellow.png) no-repeat 0 0;
}
.goodPass span{
background:url(../images/yellow.png) no-repeat top right;
}
.strongPass{
background:url(../images/green.png) no-repeat 0 0;
}
.strongPass span{
background:url(../images/green.png) no-repeat top right;
}

head部分代碼
head
復制代碼 代碼如下:

<title>無標題頁</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<!-- custom select plugin js -->
<script type="text/javascript" src="js/password_strength_plugin.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
$(document).ready( function() {
//BASIC
$(".password_test").passStrength({
userid: "#user_id"
});
//ADVANCED
$(".password_adv").passStrength({
shortPass: "top_shortPass",
badPass: "top_badPass",
goodPass: "top_goodPass",
strongPass: "top_strongPass",
baseStyle: "top_testresult",
userid: "#user_id_adv",
messageloc: 0
});
});
</script>

body部分代碼
body
復制代碼 代碼如下:

<body>
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td align="right"><label>User Name:</label></td>
<td><input type="text" name="user_name" id="user_id_adv"/></td>
</tr>
<tr>
<td align="right"><label>Password:</label></td>
<td><input type="password" name="pass_word" class="password_adv"/></td>
</tr>
</table>
</body>

相關文章

  • jquery中通過父級查找進行定位示例

    jquery中通過父級查找進行定位示例

    如果想要查找到有icon這個class的span除了用原始的代碼還可以用父級查詢的方法進行定位,具體的實現如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
    2013-06-06
  • javascript截圖 jQuery插件imgAreaSelect使用詳解

    javascript截圖 jQuery插件imgAreaSelect使用詳解

    這篇文章主要介紹了avascript截圖 jQuery插件imgAreaSelect使用詳解,需要的朋友可以參考下
    2016-05-05
  • jQuery移動端圖片上傳組件

    jQuery移動端圖片上傳組件

    這篇文章主要介紹了jQuery移動端圖片上傳組件,使用File API+canvas 客戶端壓縮圖片,并實現文件上傳服務端,感興趣的小伙伴們可以參考一下
    2016-06-06
  • jQuery表單對象屬性過濾選擇器實例詳解

    jQuery表單對象屬性過濾選擇器實例詳解

    這篇文章主要介紹了jQuery表單對象屬性過濾選擇器,結合實例形式詳細分析了jQuery針對表單元素進行屬性過濾操作的具體實現技巧,需要的朋友可以參考下
    2016-09-09
  • php結合imgareaselect實現圖片裁剪

    php結合imgareaselect實現圖片裁剪

    這篇文章主要介紹了php結合imgareaselect實現圖片裁剪的相關資料,需要的朋友可以參考下
    2015-07-07
  • jQuery.Form實現Ajax上傳文件同時設置headers的方法

    jQuery.Form實現Ajax上傳文件同時設置headers的方法

    這篇文章主要介紹了jQuery.Form實現Ajax上傳文件同時設置headers的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-06-06
  • jQuery實現加入購物車飛入動畫效果

    jQuery實現加入購物車飛入動畫效果

    當您在電商購物網站瀏覽中意的商品時,您可以點擊頁面中的“加入購物車”按鈕即可將商品加入的購物車中。本文介紹借助一款基于jQuery的動畫插件,點擊加入購物車按鈕時,實現商品將飛入到右側的購物車中的效果。
    2015-03-03
  • IE8下jQuery改變png圖片透明度時出現的黑邊

    IE8下jQuery改變png圖片透明度時出現的黑邊

    這些天在做一個效果,鼠標經過,PNG圖片由透明變成不透明, 但是會出現黑邊,晚上查了好多辦法,分別對IE8設置過濾器啊等等,都不見效果。最終在熱心網友的幫助下解決了問題,下面我們就來分析下
    2015-08-08
  • JQuery異步post上傳表單數據標準化模板

    JQuery異步post上傳表單數據標準化模板

    這篇文章主要介紹了JQuery異步post上傳表單數據標準化模板,主要分享詳細的代碼,具有一的的知識參考性,需要的小伙伴可以參考一下
    2022-02-02
  • jQuery中$this和$(this)的區(qū)別介紹(一看就懂)

    jQuery中$this和$(this)的區(qū)別介紹(一看就懂)

    這篇文章主要介紹了jQuery中$this和$(this)的區(qū)別介紹(一看就懂),本文用簡潔的語言講解了它們之間的區(qū)別,并給出了一個例子來說明,需要的朋友可以參考下
    2015-07-07

最新評論

通江县| 庆元县| 石景山区| 宿迁市| 汨罗市| 日土县| 正定县| 如东县| 健康| 锡林浩特市| 丽江市| 裕民县| 永和县| 临江市| 社旗县| 道孚县| 永兴县| 平原县| 喀喇沁旗| 玉山县| 霞浦县| 府谷县| 德昌县| 石狮市| 绥中县| 清镇市| 额尔古纳市| 龙南县| 加查县| 哈尔滨市| 赞皇县| 丹阳市| 红河县| 潍坊市| 临沧市| 潞城市| 巴塘县| 井陉县| 高安市| 沂源县| 新密市|