[AS3]as3密码强度的验证操作(附源代码)
[AS3]as3密码强度的验证操作(附源代码),as3密码,as3密码验证
[AS3]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;
- else
- return 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;
- else
- return 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。
再看看如何用视图来展示密码强度,这里不多作解释了,只是一个简单的动画效果。
- private function updatestrengthview():void
- {
- var towidth:number = pwdinputview.strengthcanvas.width * checkstrong.evaluatepwd(pwdinputview.password.text) * .25;
- tweenlite.to(pwdinputview.maskcanvas, 1.5, {width:towidth, ease:bounce.easeout, overwrite:false});
- }
- private function updatestrengthview():void
- {
- var towidth:number = pwdinputview.strengthcanvas.width * checkstrong.evaluatepwd(pwdinputview.password.text) * .25;
- tweenlite.to(pwdinputview.maskcanvas, 1.5, {width:towidth, ease:bounce.easeout, overwrite:false});
- }
[AS3]as3密码强度的验证操作(附源代码)
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...