js实现密码强度检测_.docx

上传人:PIYPING 文档编号:11619227 上传时间:2021-08-26 格式:DOCX 页数:9 大小:13.16KB
返回 下载 相关 举报
js实现密码强度检测_.docx_第1页
第1页 / 共9页
js实现密码强度检测_.docx_第2页
第2页 / 共9页
js实现密码强度检测_.docx_第3页
第3页 / 共9页
js实现密码强度检测_.docx_第4页
第4页 / 共9页
js实现密码强度检测_.docx_第5页
第5页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《js实现密码强度检测_.docx》由会员分享,可在线阅读,更多相关《js实现密码强度检测_.docx(9页珍藏版)》请在三一文库上搜索。

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( backgroundColor: ); $(#middle).css( backgroundColor: ); $(#strength).css( backgroundColor: ); /script 以上这篇js实现密码强度检测【附示例】就是我分享给大家的全部内容了,盼望能给大家一个参考 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1