首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

AS3密码强度印证

2012-10-27 
AS3密码强度验证public static function evaluatePwd(sPW:String):int{ if (sPW.length 4) return 0 v

AS3密码强度验证

public static function evaluatePwd(sPW:String):int{ if (sPW.length <= 4) return 0; var Modes:int = 0; for (var i:int = 0; i < sPW.length; i++) { Modes |= CharMode(sPW.charCodeAt(i)); } return bitTotal(Modes); function CharMode(iN:int):int{ if (iN>=48 && iN <=57) return 1; if (iN>=65 && iN <=90) return 2; if (iN>=97 && iN <=122) return 4; elsereturn 8; } function bitTotal(num:int):* { var modes:int = 0; for (var i:int = 0; i < 4; i++) { if (num & 1) modes ++; num >>>= 1; } return modes; } }public static function evaluatePwd(sPW:String):int{if (sPW.length <= 4)return 0;var Modes:int = 0;for (var i:int = 0; i < sPW.length; i++){Modes |= CharMode(sPW.charCodeAt(i));}return bitTotal(Modes);function CharMode(iN:int):int{if (iN>=48 && iN <=57)return 1;if (iN>=65 && iN <=90)return 2;if (iN>=97 && iN <=122)return 4;elsereturn 8;}function bitTotal(num:int):*{var modes:int = 0;for (var i:int = 0; i < 4; i++){if (num & 1) modes ++;num >>>= 1;}return modes;}}另外还有一个十分简单的算法public static function evaluatePwd2(sPW:String):int{ return sPW.replace(/^(?:([a-z])|([A-Z])|([0-9])|(.)){5,}|(.)+$/g, “$1$2$3$4$5″).length; }public static function evaluatePwd2(sPW:String):int{return sPW.replace(/^(?:([a-z])|([A-Z])|([0-9])|(.)){5,}|(.)+$/g, "$1$2$3$4$5").length;}我们可以用多种图形化的界面甚至动画去展现密码的强度,举个简单的例子,例如我希望用户在输入密码后1秒内没有任何输入动作,则验证密码的强度,并且已进度条的形式展示首先注册一个监听pwdInputView.password.addEventListener(KeyboardEvent.KEY_UP, onKey);pwdInputView.password.addEventListener(KeyboardEvent.KEY_UP, onKey);然后看看监听函数private var oldText:String; private function onKey(e:KeyboardEvent):void{ if (oldText != pwdInputView.password.text && pwdInputView.password.text.length > 5) { oldText = pwdInputView.password.text; TweenLite.killTweensOf(updateStrengthView, false); TweenLite.delayedCall(1, updateStrengthView); } }private var oldText:String;private function onKey(e:KeyboardEvent):void{if (oldText != pwdInputView.password.text && pwdInputView.password.text.length > 5){oldText = pwdInputView.password.text;TweenLite.killTweensOf(updateStrengthView, false);TweenLite.delayedCall(1, updateStrengthView);}}首先定义一个oldText成员,用于记录上次输入的密码,如果当前密码和上次密码不相同并且长度大于5,开始执行操作。我这里用了TweenLite作为计时器,1秒后将执行强度判断,如果发现用户在1秒内再次有输入操作,则销毁当前TweenLite。再看看blog_bottom">          2009-12-28 12:46      浏览 137      评论(0)                  分类:企业架构            
  • 相关推荐

  • 热点排行