仿google密码强度判断
来源:ASP学习网 作者:Admin 时间:08-08-05 点击:
灵感来自GOOGLE--Gmail的注册表单,这是结合XMLHTTP和servlet以及客户端脚本Javascript来实现的一个给死板的表单程序增加亲和力的一个小玩意。
下午看到遂花了几小时模仿着写了一个。前端代码均来自GMAIL的表单注册那里,后段验证密码强度的servlet是自己做的,算法有待商戳不过效果算是出来了。
先来看客户端的JS代码,命名文 gvUserReg.js
程序代码:
程序代码:
// this code powered by google
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all && !is_op;
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
if (is_ie) {
// Guaranteed to be ie5 or ie6
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
try {
xmlhttp = new ActiveXObject(control);
xmlhttp.onreadystatechange = handler;
} catch (ex) {
// TODO: better help message
alert("You need to enable active scripting and activeX controls");
}
} else {
// Mozilla
xmlhttp = new XMLHttpRequest();
xmlhttp.onload = handler;
xmlhttp.onerror = handler;
}
return xmlhttp;
}
alert();
// XMLHttp send POST request
function XmlHttpPOST(xmlhttp, url, data) {
try {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(data);
} catch (ex) {
// do nothing
}
}
// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
try {
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
} catch (ex) {
// do nothing
}
}
var myxmlhttp;
var isBrowserCompatible;
var hidePasswordBar;
ratingMsgs = new Array(6);
ratingMsgColors = new Array(6);
barColors = new Array(6);
ratingMsgs[0] = "未评级";
ratingMsgs[1] = "太短";
ratingMsgs[2] = "弱";
ratingMsgs[3] = "一般";
ratingMsgs[4] = "很好";
ratingMsgs[5] = "极佳"; //If the password server is down
ratingMsgColors[0] = "#808080";
ratingMsgColors[1] = "#da5301";
ratingMsgColors[2] = "#ccbe00";
ratingMsgColors[3] = "#1e91ce";
ratingMsgColors[4] = "#0000FF";
ratingMsgColors[5] = "#ff0000";
barColors[0] = "#e0e0e0";
barColors[1] = "#da5301";
barColors[2] = "#f0e54b";
barColors[3] = "#1e91ce";
barColors[4] = "#0000FF";
barColors[5] = "#ff0000";
hidePasswordBar = false;
function CreateRateUserPassReq(formKey) {
if (!isBrowserCompatible) {
return;
}
var passwd = document.forms[formKey].gvUserPass.value;
var min_passwd_len = 6;
var passwdKey = "passwd";
if (p