XMLHTTP和servlet以及客户端脚本Javascript来实现 密码强度判断
程序代码如下:// 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;