密码安全等级

1.五级

checkPassword(){
let vm=this;
if(vm.newPassword){
let levelValue=0;
let level=vm.getPasswordSecurityLevel(vm.newPassword);
console.log(level);
if(level==0){
levelValue='很弱';
}else if(level==1){
levelValue='弱';
}else if(level==2){
levelValue='中等';
}else if(level==3){
levelValue='强';
}else if(level==4){
levelValue='很强';
}else{
levelValue='超强';
}
$("#cp").removeClass().addClass("password1"+level) .html("密码安全级别:"+levelValue);
}
},
getPasswordSecurityLevel(password){
console.log(( password.length > 5 ));
console.log(( /[a-z]/.test(password) && /[A-Z]/.test(password) ));
console.log(( /d/.test(password) && /D/.test(password) ));
console.log(( /[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(password) && /w/.test(password) ));
console.log(( password.length > 12 ));
return 0
//密码长度大于5位
+( password.length > 5 )
//密码含有字母
+( /[a-z]/.test(password) && /[A-Z]/.test(password) )
//密码含有字母和数字
+( /d/.test(password) && /D/.test(password) )
//密码含有特殊字符
+( /[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(password) && /w/.test(password) )
//密码长度大于12位
+( password.length > 12 );
},
2.三级
checkPassword(){
let vm=this;
if(vm.newPassword&&vm.newPassword!=''){
let level=vm.getPasswordSecurityLevel(vm.newPassword);
if(level<3){
vm.levelValue='弱';
vm.level=1;
}else if(level==3){
vm.levelValue='中等';
vm.level=2;
}else if(level>3){
vm.levelValue='强';
vm.level=3;
}
}
},
getPasswordSecurityLevel(password){
return 0
//密码长度大于5位
+( password.length > 5 )
//密码含有字母
+( /[a-z]/.test(password) && /[A-Z]/.test(password) )
//密码含有字母和数字
+( /d/.test(password) && /D/.test(password) )
//密码含有特殊字符
+( /[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(password) && /w/.test(password) )
//密码长度大于12位
+( password.length > 12 );
},
html:
<p id="cp" v-show="newPassword"><button class="fa-window-minimize-o" :class="{password10:level<1,password11:level>0}"></button><button class="fa-window-minimize" :class="{password10:level<1,password12:level>1}"></button><button class="fa-window-minimize" :class="{password10:level<1,password13:level>2}"></button><b>{{levelValue}}</b></p>

css:
<style>
.password10 {background:#dcf2f8;}
.password11 {background:#00FF00;}
.password12 {background:#FF9900;}
.password13 {background:#FF0000;}
#cp{
font-size: 13px;
display: inline-block;
margin-left: 25px;
margin-bottom: 0;
130px;
}
#cp>button{
padding:3px 16px;
border:0;
}
#cp>b{
padding-left:4px;
position:relative;
top:4px;
}
</style>
原文地址:https://www.cnblogs.com/cx709452428/p/7601594.html