js实现密码强度检测__第1页
js实现密码强度检测__第2页
js实现密码强度检测__第3页
js实现密码强度检测__第4页
js实现密码强度检测__第5页
免费预览已结束,剩余4页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、js实现密码强度检测_ 这篇文章主要介绍了js实现密码强度检测的相关实例,第一个例子给出了全部代码,可以挺直运行,其次个例子只给出了js代码,感爱好的码农可以自己完成其次个实例。 第一个实例 这段JavaScript代码比较有用,它完成用户注册时推断用户输入密码的强度,分强、弱、中三等级,它可以依据用户输入的密码显示对应的密码强弱等级,便利用户改进输入。 实现代码: html head titleJS推断密码强度/title script language=javascript /推断输入密码的类型 function CharMode(iN) if (iN=48 iN =57) /数字 ret

2、urn 1; if (iN=65 iN =90) /大写 return 2; if (iN=97 iN =122) /小写 return 4; else return 8; /bitTotal函数 /计算密码模式 function bitTotal(num) modes=0; for (i=0;i4;i+) if (num 1) modes+; num=1; return modes; /返回强度级别 function checkStrong(sPW) if (sPW.length=4) return 0; /密码太短 Modes=0; for (i=0;isPW.length;i+) /密码

3、模式 Modes|=CharMode(sPW.charCodeAt(i); return bitTotal(Modes); /显示颜色 function pwStrength(pwd) O_color=#eeeeee; L_color=#FF0000; M_color=#FF9900; H_color=#33CC00; if (pwd=null|pwd=) Lcolor=Mcolor=Hcolor=O_color; else S_level=checkStrong(pwd); switch(S_level) case 0: Lcolor=Mcolor=Hcolor=O_color; case

4、1: Lcolor=L_color; Mcolor=Hcolor=O_color; break; case 2: Lcolor=Mcolor=M_color; Hcolor=O_color; break; default: Lcolor=Mcolor=Hcolor=H_color; document.getElementById(strength_L).style.background=Lcolor; document.getElementById(strength_M).style.background=Mcolor; document.getElementById(strength_H).

5、style.background=Hcolor; return; /script /head body form name=form1 action= 密码:input type=password size=8 onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value) br密码强度: table width=210 border=1 cellspacing=0 cellpadding=1 bordercolor=#eeeeee height=22 style=display:inline tr align=center bgcol

6、or=#f5f5f5 td width=33% id=strength_L弱/td td width=33% id=strength_M中/td td width=33% id=strength_H强/td /tr /table /form /body /html 其次个实例: script function AuthPasswd(string) if (string.length = 6) if (/a-zA-Z+/.test(string) /0-9+/.test(string) /W+D+/.test(string) noticeAssign(1); else if (/a-zA-Z+/

7、.test(string) | /0-9+/.test(string) | /W+D+/.test(string) if (/a-zA-Z+/.test(string) /0-9+/.test(string) noticeAssign( - 1); else if (/a-zA-Z+/.test(string) /W+D+/.test(string) noticeAssign( - 1); else if (/0-9+/.test(string) /W+D+/.test(string) noticeAssign( - 1); else noticeAssign(0); else noticeA

8、ssign(null); function noticeAssign(num) if (num = 1) $(#weak).css( backgroundColor: #009900 ); $(#middle).css( backgroundColor: #009900 ); $(#strength).css( backgroundColor: #009900 ); $(#strength).html(很强); $(#middle).html(); $(#weak).html(); else if (num = -1) $(#weak).css( backgroundColor: #ffcc3

9、3 ); $(#middle).css( backgroundColor: #ffcc33 ); $(#strength).css( backgroundColor: ); $(#weak).html(); $(#middle).html(中); $(#strength).html(); else if (num = 0) $(#weak).css( backgroundColor: #dd0000 ); $(#middle).css( backgroundColor: ); $(#strength).css( backgroundColor: ); $(#weak).html(弱); $(#middle).html(); $(#strength).html(); else $(#weak).html( ); $(#middle).html( ); $(#strength).html( ); $(#weak).css( b

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论