仿google密码强度判断 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Mar 9

仿google密码强度判断 不指定

tommyhu , 14:14 , ASP , Comments(0) , Trackbacks(0) , Reads(8802) , Via Original Large | Medium | Small
先来看客户端的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 (passwd.length < min_passwd_len) {
     DrawBar(1);
    }else{
     //We need to escape the password now so it won't mess up with length test
      passwd = escape(passwd);
      var params = passwdKey + "=" + passwd
      myxmlhttp = CreateXmlHttpReq(RateUserPassXmlHttpHandler);
      XmlHttpPOST(myxmlhttp, "/club/rateUserPass.gv", params);
    }
  }

  function getElement(name) {
    if (document.all) {
      return document.all(name);
    }
    return document.getElementById(name);
  }

  function RateUserPassXmlHttpHandler() {
    // Can't check status since safari doesn't support it
    if (myxmlhttp.readyState !=4 ) {
      return;
    }
    rating = parseInt(myxmlhttp.responseText);
    DrawBar(rating);
  }

  function DrawBar(rating) {
    var posbar = getElement('posBar');
    var negbar = getElement('negBar');
    var passwdRating = getElement('passwdRating');
    var barLength = getElement('passwdBarDiv').width;
    if (rating >= 0 && rating <= 5) {  //We successfully got a rating
      posbar.style.width = barLength / 5 * rating;
      negbar.style.width = barLength / 5 * (5 - rating);
    } else {
      posbar.style.width = 0;
      negbar.style.width = barLength;
      rating = 5; // Not rated Rating
    }
    posbar.style.background = barColors[rating]
    passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] +
                             "'>" + ratingMsgs[rating] + "</font>";
  }
表单部分只是列出密码选框部分
▲返回顶部

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot