这个有时候会用在密码的判断上,使用MD5存储的密码就是管理员也不知道用户的密码是多少,在数据库里面是使用MD5加密后的字符串存储的,验证的时候是将用户输入的密码再次以MD5加密,然后和存储在数据库里的原字符串比较
JS判断,一般是客气端的验证,一般用来判断是否为空,两次输入的密码是否一样,它不会读取数据库,也不能可能和存储在数据库中的数据进行验证~~
你好帮你分析了一下 ,错误在不能像 p1.focus() 这样有错误 应该用document.getElementById("pwd1").focus() 我调试的代码如下:运行没有错误:
<script language="javascript">
function checkForm(){
var p1=document.getElementById("pwd1").value
var p2=document.getElementById("pwd2").value
if(p1!==p2) {
alert("密码不正确!")
document.getElementById("pwd1").focus() //用上这一句之后如果输错了光标到不了下一个只能用键盘的tab移动光标
return false
} else{
alert("密码输入正确")
return true
}
}
</script>
</head>
<body>
<input type="text" id="pwd1" name="pwd1" value="" />
<input type="text" id="pwd2" name="pwd1" value="" onclick="checkForm()"/>
</body>
这段JavaScript代码比较实用,它完成用户注册时判断用户输入密码的强度,分强、弱、中三等级,它可以根据用户输入的密码显示对应的密码强弱等级,方便用户改进输入 。<html>
<head>
<title>JS判断密码强度</title>
<script language=javascript>
//判断输入密码的类型
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=0i<4i++){
if (num &1) modes++
num>>>=1
}
return modes
}
//返回强度级别
function checkStrong(sPW){
if (sPW.length<=4)
return 0//密码太短
Modes=0
for (i=0i<sPW.lengthi++){
//密码模式
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 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>
<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" bgcolor="#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>