<html>
<head>

<meta http-equiv="content-type" content="text/html"; charset="utf-8"/>

<script src="./js/jquery-1.8.0.min.js"></script>

<script type="text/javascript">

//CharMode函数  

//测试某个字符是属于哪一类.  

function CharMode(iN){  

if (iN>=48 && iN <=57) //数字  

return 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;i<4;i++){  

if (num & 1) modes++;  

num>>>=1;  

}  

return modes;  

}

//checkStrong函数  

//返回密码的强度级别

function checkStrong(sPW){  

if (sPW.length<=4)  

return 0; //密码太短  

Modes=0;  

for (i=0;i<sPW.length;i++){  

//测试每一个字符的类别并统计一共有多少种模式.  

Modes|=CharMode(sPW.charCodeAt(i));  

}

return bitTotal(Modes);

}

//pwStrength函数  

//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色

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 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").style.background=Hcolor;  

return;  

}   

</script>

</head>

<body>

<div>

<form name="form1" action="" >  

输入密码:<input type="password" size="15" onKeyUp="pwStrength(this.value)" onBlur="pwStrength(this.value)">  

<br/>密码强度:  

<table width="217" border="1" cellspacing="0" cellpadding="1" bordercolor="#cccccc" height="23" style='display:inline'>  

<tr align="center" bgcolor="#eeeeee">

<td width="33%" id="strength_L">弱</td>  

<td width="33%" id="strength_M">中</td>  

<td width="33%" id="strength_H">强</td>  

</tr>  

</table>

</form>

</div>

</body>

</html>

js实现密码强度验证的更多相关文章

  1. 这篇文章主要为大家详细介绍了jQuery密码强度验证控件使用详解的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    本文实例为大家分享了jQuery密码强度验证控件,供大家参考,具体内容如下 <html>   <head>     <meta http-equiv="Cont ...

  2. 正则表达式之js检验密码强度

    最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...

  3. MySQL密码强度验证修改

    MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格. 影响的语句和函数有:create user,grant,set password,pas ...

  4. js判断密码强度

    html代码: <form name="form1" action=""> 密码:<input type="password&quo ...

  5. js 检验密码强度

    html 代码如下: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset=&quo ...

  6. 【javascript】js 检验密码强度

    最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...

  7. js实现密码强度

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. javascript密码强度验证!

    //CharMode函数 //测试某个字符是属于哪一类 function CharMode(iN) { if (iN>=48 && iN <=57) //数字 return ...

  9. Js判断密码强度并显示提示信息

    用javascipt实现的Ajax判断密码强弱的功能,大多数有用户注册功能的网站,都会有这么一个功能,作为WEB程序员,应该会写这种小模块哦,不懂的就看下这个例子,觉得挺简单,当初帮助了不少人学会了密 ...

随机推荐

  1. ThinkPHP - I 函数

    ThinkPHP函数详解:I方法   浏览:144722 发布日期:2013/06/01 分类:文档教程 关键字: 函数 ThinkPHP的I方法是3.1.3版本新增的,如果你是之前的3.*版本的话, ...

  2. android 4.2 root

    前一段因工作需要,对android4.2 进行root.但是在下载了 点击打开链接,下载了Superuser.apk,把对应的apk拷贝到system/app,su拷贝到/system/bin 与/s ...

  3. memcache 在php存取中的应用

    当用户刷新网页或有大量用户访问网站时,就会产生大量数据库查询进程,这不但拖慢了网页打开速度,同时也给服务器带来了很大压力. 作为php菜鸟,今天刚刚接触到了 memcache 这个东东,于是自己跟着文 ...

  4. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  5. 开发板ip设置

    vi /etc/init.d/rcS 在其中加入 ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up 就可以了

  6. Linux下安装jekyll

    折腾了大半天,终于搞定了,这可得记下来了. 我的Linux版本:CentOS 6.5 主要的安装顺序还是官网上的说明:http://jekyllrb.com/docs/installation/,所以 ...

  7. 基于visual Studio2013解决C语言竞赛题之0525拉丁方阵

     题目

  8. eclipse处理长字符串拼接快捷方法类

    情景: 你在后台写sql文访问数据库时是不是要这样写 String sql="select a," +"b," +"c " +"f ...

  9. debian支持ll命令

    debian支持ll命令 $ ll -bash: ll: command not found 没有ll这个命令.尽管也知道ll事实上 是ls -l 这个命令的别名,可是总感觉不是非常习惯.由于之前一直 ...

  10. GCD其他实用场景

    GCD线程间通信 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);     ...