增加了jquery密码强度验证插件passwordStrength

This commit is contained in:
Li Jianxuan 2011-12-14 08:49:16 +00:00
parent ee7a6afd8d
commit 8cb7c2b3b6
3 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,33 @@
.is0 {
BACKGROUND: url(../img/progressImg1.png) no-repeat 0px 0px; WIDTH: 138px; HEIGHT: 7px
}
.is10 {
BACKGROUND-POSITION: 0px -7px
}
.is20 {
BACKGROUND-POSITION: 0px -14px
}
.is30 {
BACKGROUND-POSITION: 0px -21px
}
.is40 {
BACKGROUND-POSITION: 0px -28px
}
.is50 {
BACKGROUND-POSITION: 0px -35px
}
.is60 {
BACKGROUND-POSITION: 0px -42px
}
.is70 {
BACKGROUND-POSITION: 0px -49px
}
.is80 {
BACKGROUND-POSITION: 0px -56px
}
.is90 {
BACKGROUND-POSITION: 0px -63px
}
.is100 {
BACKGROUND-POSITION: 0px -70px
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

View File

@ -0,0 +1,62 @@
$.fn.passwordStrength = function(options){
return this.each(function(){
var that = this;that.opts = {};
that.opts = $.extend({}, $.fn.passwordStrength.defaults, options);
that.div = $(that.opts.targetDiv);
that.defaultClass = that.div.attr('class');
that.percents = (that.opts.classes.length) ? 100 / that.opts.classes.length : 100;
v = $(this).keyup(function(){
if( typeof el == "undefined" )
this.el = $(this);
var s = getPasswordStrength (this.value);
var p = this.percents;
var t = Math.floor( s / p );
if( 100 <= s ) t = this.opts.classes.length - 1;
this.div.removeAttr('class').addClass( this.defaultClass ).addClass( this.opts.classes[ t ]);
})
});
//»ñÈ¡ÃÜÂëÇ¿¶È
function getPasswordStrength(H){
var D=(H.length);
if(D>5){
D=5
}
var F=H.replace(/[0-9]/g,"");
var G=(H.length-F.length);
if(G>3){G=3}
var A=H.replace(/\W/g,"");
var C=(H.length-A.length);
if(C>3){C=3}
var B=H.replace(/[A-Z]/g,"");
var I=(H.length-B.length);
if(I>3){I=3}
var E=((D*10)-20)+(G*10)+(C*15)+(I*10);
if(E<0){E=0}
if(E>100){E=100}
return E
}
};
$.fn.passwordStrength.defaults = {
classes : Array('is10','is20','is30','is40','is50','is60','is70','is80','is90','is100'),
targetDiv : '#passwordStrengthDiv',
cache : {}
}
$.passwordStrength = {};
$.passwordStrength.getRandomPassword = function(size){
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var size = size || 8;
var i = 1;
var ret = ""
while ( i <= size ) {
$max = chars.length-1;
$num = Math.floor(Math.random()*$max);
$temp = chars.substr($num, 1);
ret += $temp;
i++;
}
return ret;
}