JavaScript密码强度检测

http://jhxk.javaeye.com/upload/attachment/116881/2e20756c-15b6-3a0e-98f0-910aab22e40e.jpg

 

Html代码 复制代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title>密码强度检测</title>  
  5. <META http-equiv=Content-Type content="text/html; charset=utf-8">  
  6.     <style type="text/css">  
  7.     body {font-size:12px}   
  8.     .pwd-strength-box,   
  9.     .pwd-strength-box-low,   
  10.     .pwd-strength-box-med,   
  11.     .pwd-strength-box-hi   
  12.     {   
  13.     color: #464646;   
  14.     text-align: center;   
  15.     width: 40px;   
  16.     }   
  17.     .pwd-strength-box-low   
  18.     {   
  19.     color: #CCCCCC;   
  20.     background-color: #E0FFA2;   
  21.     width: 40px;   
  22.     }   
  23.     .pwd-strength-box-med   
  24.     {   
  25.     color: #666666;   
  26.     background-color: #D1FF46;   
  27.     width: 40px;   
  28.     }   
  29.     .pwd-strength-box-hi   
  30.     {   
  31.     color: #000000;   
  32.     background-color: #C0F000;   
  33.     width: 40px;   
  34.     }   
  35. </style>  
  36.   
  37.     <script type="text/javascript">  
  38.     /*   
  39.  函数名称:trim()   
  40.  函数功能: 去掉字符串的前后空格   
  41.  传入参数:字符串变量   
  42.  传出结果:去掉前后空格后的字符串   
  43. */   
  44. function trim(srcStr)   
  45. {   
  46.  var i,j,len;   
  47.   len=srcStr.length;   
  48.  for(i=0;i<len;i++)   
  49.   if(srcStr.charAt(i)!=' ') break;   
  50.  for(j=len-1;j>=i;j--)   
  51.   if(srcStr.charAt(j)!=' ') break;   
  52.  if(i>j)    
  53.   return "";   
  54.   else    
  55.   return srcStr.substr(i,j-i+1);   
  56. }   
  57. function $(obj)   
  58. {   
  59.     return document.getElementById(obj);   
  60. }   
  61. //检查密码等级   
  62. function checkpwdlevel(pwd)   
  63. {   
  64.     var objLow=document.getElementById("pwdLow");   
  65.     var objMed=document.getElementById("pwdMed");   
  66.     var objHi=document.getElementById("pwdHi");   
  67.     objLow.className="pwd-strength-box";   
  68.     objMed.className="pwd-strength-box";   
  69.     objHi.className="pwd-strength-box";   
  70.     if(pwd.length<6)   
  71.     {   
  72.         objLow.className="pwd-strength-box-low";   
  73.     }   
  74.     else   
  75.     {   
  76.         var p1= (pwd.search(/[a-zA-Z]/)!=-1) ? 1 : 0;   
  77.         var p2= (pwd.search(/[0-9]/)!=-1) ? 1 : 0;   
  78.         var p3= (pwd.search(/[^A-Za-z0-9_]/)!=-1) ? 1 : 0;   
  79.         var pa=p1+p2+p3;   
  80.         if(pa==1)   
  81.         {   
  82.             objLow.className="pwd-strength-box-low";   
  83.         }   
  84.         else if(pa==2)   
  85.         {   
  86.             objLow.className="pwd-strength-box-low";   
  87.             objMed.className="pwd-strength-box-med";   
  88.         }   
  89.         else if(pa==3)   
  90.         {   
  91.             objLow.className="pwd-strength-box-low";   
  92.             objMed.className="pwd-strength-box-med";   
  93.             objHi.className="pwd-strength-box-hi";   
  94.         }   
  95.     }   
  96. }   
  97.     </script>  
  98.   
  99. </head>  
  100. <body>  
  101.     <table width="100%" border="0" cellspacing="0">  
  102.         <tr>  
  103.             <td height="32" align="right" style="width: 83px">  
  104.                 密码:</td>  
  105.             <td align="left">  
  106.                 <input id="password" type="password" size="18" name="userpwd" runat="server" onkeyup="javascript:checkpwdlevel(this.value);"  
  107.                     class="register_input" /></td>  
  108.         </tr>  
  109.         <tr>  
  110.             <td height="32" align="right" style="width: 83px">  
  111.                 安全性等级:</td>  
  112.             <td align="left">  
  113.                 <table style="border-left: 1px solid #7CA001; border-top: 1px solid #7CA001; border-right: 1px solid #7CA001;   
  114.                     border-bottom: 1px solid #7CA001;" cellspacing="0" cellpadding="0" width="120px">  
  115.                     <tbody>  
  116.                         <tr>  
  117.                             <td class="pwd-strength-box" id="pwdLow" style="width: 40px; height: 16px" align="center"  
  118.                                 valign="bottom">  
  119.                                 弱</td>  
  120.                             <td class="pwd-strength-box" id="pwdMed" style="width: 40px; height: 16px" align="center"  
  121.                                 valign="bottom">  
  122.                                 中</td>  
  123.                             <td class="pwd-strength-box" id="pwdHi" style="width: 40px; height: 16px" align="center"  
  124.                                 valign="bottom">  
  125.                                 强</td>  
  126.                         </tr>  
  127.                     </tbody>  
  128.                 </table>  
  129.             </td>  
  130.         </tr>  
  131.     </table>  
  132. </body>  
  133. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值