JavaScriptパスワード強度検証
2104 ワード
これは簡単で不思議なパスワード強度の検証例です.
<script type="text/javascript">
var $ = function(v){return document.getElementById(v);}
function isSecurity(v){
if (v.length < 3) { iss.reset();return;}
var lv = -1;
if (v.match(/[a-z]/ig)){lv++;}
if (v.match(/[0-9]/ig)){lv++;}
if (v.match(/(.[^a-z0-9])/ig)){lv++;}
if (v.length < 6 && lv > 0){lv--;}
iss.reset();
switch(lv) {
case 0:
iss.level0();
break;
case 1:
iss.level1();
break;
case 2:
iss.level2();
break;
default:
iss.reset();
}
}
var iss = {
color:["CC0000","FFCC33","66CC00","CCCCCC"],
text:[" "," "," "],
width:["50","100","150","10"],
reset:function(){
$("B").style.backgroundColor = iss.color[3];
$("B").style.width = iss.width[3];
$("A").innerHTML = "";
},
level0:function(){
$("B").style.backgroundColor = iss.color[0];
$("B").style.width = iss.width[0];
$("A").innerHTML = " ";
},
level1:function(){
$("B").style.backgroundColor = iss.color[1];
$("B").style.width = iss.width[1];
$("A").innerHTML = " ";
},
level2:function(){
$("B").style.backgroundColor = iss.color[2];
$("B").style.width = iss.width[2];
$("A").innerHTML = " ";
}
}
</script>
<table border="0" style="border-collapse:collapse;">
<tr>
<td> :<input type="password" size=50 maxlength=20 onkeyup="isSecurity(this.value);"></td>
<td bgcolor="#EEEEEE" id="B"></td>
<td id="A"> </td>
</tr>
</table>