手机版

js密码强度检测

时间:2021-09-19 来源:互联网 编辑:宝哥软件园 浏览:

本文实例讲解了射流研究…密码强度检测的实现代码,分享给大家供大家参考,具体内容如下

运行效果图:

这段Java脚本语言代码比较实用,它完成用户注册时判断用户输入密码的强度,分强、弱、中三等级,它可以根据用户输入的密码显示对应的密码强弱等级,方便用户改进输入。

实现代码:

htmlheadtitleJS判断密码强度/titlescript语言=javascript /判断输入密码的类型函数CharMode(iN){ if (iN=48 iN=57) //数字返回1;if (iN=65 iN=90) //大写返回2;if (iN=97 iN=122) //小写返回4;否则返回8;} //bitTotal函数//计算密码模式函数BitTotal(num){ modes=0;for(I=0;i4;i ){ if (num 1)模式;num=1;}返回模式;} //返回强度级别函数CheckStrong(SPw){ if(SPw。长度=4)返回0;//密码太短modes=0;for(I=0;isPW.lengthi ){ //密码模式modes |=CharMode(SPw)。charcodeat(I));}返回bitTotal(模式);} //显示颜色函数pw强度(pwd){ O _ color=' # eeee ';l _ color=' # ff 0000m _ color=' # ff 9900h _ color=' # 33 cc 00 if(pwd==null | | pwd==' '){ Lcolor=Mcolor=Hcolor=O _ color;} else { S _ level=CheckStrong(pwd);开关(S _ level){ case 0: Lcolor=Mcolor=Hcolor=O _ color;案例1: Lcolor=L _ colorMcolor=Hcolor=O _ color打破;case 2: Lcolor=Mcolor=M _ color;Hcolor=O _ color打破;默认: Lcolor=Mcolor=Hcolor=H _ color;} }文档。getelementbyid(' strength _ L ')。风格。背景=Lcolor文件。getelementbyid(' strength _ M ')。风格。背景=Mcolor文件。getelementbyid(' strength _ H ')。风格。背景=Hcolor返回;}/脚本/床头表单名称=form1操作=' '密码:输入类型=密码大小=8 OnKeyUp=pw强度(这个。值)OnBlur=pw强度(这个。值)br密码强度:表格宽度='210 '边框='1 '单元格间距='0 '单元格填充=' 1 ' bordercolor=' # eeee ' height=' 22 ' style=' display : inline ' tr align=' center ' bgcolor=' # f5f 5 ' TD width=' 33% ' id=' strength _ L '弱TD/TD宽度='33%' id='strength_M '中TD TD TD宽度='33%' id='strength_H '强/td /tr /table /form/body/html这一款先看一看效果图。

具体内容:

脚本函数AuthPasswd(字符串){ if(字符串。长度=6){ if(/[a-Za-Z]/.测试(字符串)/[0-9] /.测试(字符串)/\W \D /.test(string)){ notice sign(1);}else if(/[a-zA-Z] /.测试(字符串)|| /[0-9] /.测试(字符串)|| /\W \D /.test(string)) { if(/[a-zA-Z] /.测试(字符串)/[0-9] /.test(string)){ notice sign(-1);}else if(/\[a-zA-Z] /.测试(字符串)/\W \D /.test(string)){ notice sign(-1);}else if(/[0-9] /.测试(字符串)/\W \D /.test(string)){ notice sign(-1);} else { note sign(0);} } } else { note sign(null);}}函数注意符号(num){ if(num==1){ $(' # weak ').CSS({背景色: ' # 009900 ' });$(“# middle”).CSS({背景色: ' # 009900 ' });$(' #强度').CSS({背景色: ' # 009900 ' });$(' #强度').html(")很强');$(“# middle”).html(" ");$(“# weak”).html(" ");}else if(num==-1){ $('#weak ').CSS({背景色: ' # ffcc 33 ' });$(“# middle”).CSS({背景色: ' # ffcc 33 ' });$(' #强度').CSS({背景色: ' ' });$(“# weak”).html(" ");$(“# middle”).html(")中');$(' #强度').html(" ");}else if(num==0) { $('#weak ').CSS({背景色: ' # DD 0000 ' });$(“# middle”).CSS({背景色: ' ' });$(' #强度').CSS({背景色: ' ' });$(“# weak”).html(")弱');$(“# middle”).html(" ");$(' #强度').html(" ");}else{ $('#weak ').html(" ");$(“# middle”).html(" ");$(' #强度').html(" ");$(“# weak”).CSS({背景色: ' ' });$(“# middle”).CSS({背景色: ' ' });$(' #强度').CSS({背景色: ' ' });} }/脚本以上就是本文的全部内容,希望对大家学习爪哇岛描述语言程序设计有所帮助。

版权声明:js密码强度检测是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。