密码强度检测

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Style>
		Application {
			fontSize:12px;
		}
	</mx:Style>
	<mx:Script>
		<![CDATA[
			//密码级别验证
            private function pwdInputVis():void{
            	if(txtPassword.text == ""){
            		levelOne.opaqueBackground = "16777215";
	            	levelTwo.opaqueBackground = "16777215";
	            	levelThree.opaqueBackground = "16777215";
	            	levelFour.opaqueBackground = "16777215";
	            	levelFive.opaqueBackground = "16777215";
	            	levelSix.opaqueBackground = "16777215";
	            	levelSeven.opaqueBackground = "16777215";
	            	return;
            	}
            	var num:Number = pwdStrengthCheck(txtPassword.text);
            	levelOne.opaqueBackground = "16777215";
            	levelTwo.opaqueBackground = "16777215";
            	levelThree.opaqueBackground = "16777215";
            	levelFour.opaqueBackground = "16777215";
            	levelFive.opaqueBackground = "16777215";
            	levelSix.opaqueBackground = "16777215";
            	levelSeven.opaqueBackground = "16777215";
 
            	if(num >= 90){
            		levelSeven.opaqueBackground = "39423";
            	}
            	else if(num >= 80){
            		levelSix.opaqueBackground = "6736896";
            	}
            	else if(num >= 70){
            		levelFive.opaqueBackground = "65280";
            	}
            	else if(num >= 60){
            		levelFour.opaqueBackground = "16776960";
            	}
            	else if(num >= 50){
            		levelThree.opaqueBackground = "16763904";
            	}
            	else if(num >= 25){
            		levelTwo.opaqueBackground = "16724736";
            	}
            	else if(num >= 0){
            		levelOne.opaqueBackground = "16711680";
            	}
            }
 
            //密码得分计算
            static public function pwdStrengthCheck(passStr:String):uint
			{
				if(!passStr)return 0;
				var count:uint = 0;
				count += passStr.length<=4?5:(passStr.length>=8?25:10);
				count += !passStr.match(/[a-z]/i)?0:(passStr.match(/[a-z]/) && passStr.match(/[A-Z]/)?20:10);
				count += !passStr.match(/[0-9]/)?0:(passStr.match(/[0-9]/g).length >= 3?20:10);
				count += !passStr.match(//W/)?0:(passStr.match(//W/g).length > 1?25:10);
				count += !passStr.match(/[0-9]/)||!passStr.match(/[a-z]/i)?0:(!passStr.match(//W/)?2:(!passStr.match(/[a-z]/) || !passStr.match(/[A-Z]/)?3:5));
				return count;
			}
 
			private function showPwdText():void
			{
				if(cboShow.selected){
					txtPassword.displayAsPassword = false;
				}else{
					txtPassword.displayAsPassword = true;
				}
			}
		]]>
	</mx:Script>
 
	<mx:Panel width="450" height="450" layout="absolute" horizontalCenter="0" verticalCenter="0" title="密码级别验证">
		<mx:Label text="密码" x="10" y="12"/>
		<mx:TextInput x="47" y="10" displayAsPassword="true" width="240" change="pwdInputVis();" id="txtPassword" editable="true"/>
		<mx:HRule x="0" y="48" width="100%"/>
		<mx:Label x="6" y="58" text="非常弱" width="60" textAlign="center" id="levelOne"/>
		<mx:Label x="65" y="58" text="弱" width="60" textAlign="center" id="levelTwo"/>
		<mx:Label x="124" y="58" text="一般" width="60" textAlign="center" id="levelThree"/>
		<mx:Label x="183" y="58" text="强" width="60" textAlign="center" id="levelFour"/>
		<mx:Label x="242" y="58" text="非常强" width="60" textAlign="center" id="levelFive"/>
		<mx:Label x="301" y="58" text="安全" width="60" textAlign="center" id="levelSix"/>
		<mx:Label x="360" y="58" text="非常安全" width="60" textAlign="center" id="levelSeven"/>
		<mx:TextArea x="10" y="96" width="410" height="302" enabled="true" wordWrap="true" editable="false">
			<mx:text><![CDATA[来自 Google 的密码强度评分标准
 
一、密码长度:
5 分: 小于等于 4 个字符
10 分: 57 字符
25 分: 大于等于 8 个字符
 
二、字母:
0 分: 没有字母
10 分: 全都是小(大)写字母
20 分: 大小写混合字母
 
三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于等于 3 个数字
 
四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于 1 个符号
 
五、奖励:
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号
 
最后的评分标准:
>= 90: 非常安全
•>= 80: 安全(Secure)
•>= 70: 非常强
•>= 60: 强(Strong)
•>= 50: 一般(Average)
•>= 25: 弱(Weak)
•>= 0: 非常弱]]></mx:text>
		</mx:TextArea>
		<mx:HRule x="0" y="86" width="100%"/>
		<mx:CheckBox x="295" y="10" label="显示密码明文" id="cboShow" selected="false" click="showPwdText();"/>
	</mx:Panel>
 
</mx:Application>
发布了100 篇原创文章 · 获赞 5 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/jinxinxin1314/article/details/5381024