var base= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
var K= new Array();
function getPass() {
  var goToPage = prompt("Password Required","")
  if(goToPage == null || goToPage == "") {
    history.go(-1);
  } else {    var pLength = goToPage.length;
    for (i=0; i<pLength; i++){
      K[i]=goToPage.charAt(i);
    }
    var code=0;
    var plus=1;
    for (i=0; i<pLength; i++){      for(x=0; x<62; x++){        if (K[i] == base[x]){
          if (plus == 1){
 code = code + x;
          }else{
 code = code - x;
  }
          plus = plus * (-1);        }
      }
    }    if (code==-34) {      alert("OK");    } else {
      alert("ERROR ");
    }

解决方案 »

  1.   

    <script>
    var base= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); 
    var K= new Array(); 
    //getPass();
    function getPass() { 
      var goToPage = prompt("Password Required","")   //1Z is ok
      if(goToPage == null || goToPage == "") { 
        history.go(-1); 
      } else {
        var pLength = goToPage.length; 
        for (i=0; i <pLength; i++){ 
          K[i]=goToPage.charAt(i); 
        }
        if(checkP(K)) {
          alert('OK');
        } else {
          alert('ERROR');
        }
      }
    }
    //把验证代码提取出来
    function checkP(K) {
      pLength = K.length;
      var code=0; 
      var plus=1; 
      for (i=0; i <pLength; i++){       for(x=0; x <62; x++){         if (K[i] == base[x]){
              if (plus == 1){   //0+35-1
                code = code + x;
              }else{ 
                code = code - x; //alert(code);
              } 
              plus = plus * (-1); 
            } 
          } 
        }     if (code==-34) {       return true;     } else { 
          return false;
        }
    }
    getCode();
    //循环验证,里面只给出了2位数的可能
    function getCode() {
      var arr = new Array();
        for(var j=0;j<62;j++)
          for(var k=0;k<62;k++) {
            var arr = new Array();
            arr[0] = base[j];
            arr[1] = base[k];
            if(checkP(arr)) {
              alert(arr+' is OK');
              break;
            }
          }
         alert('over');
    }
    </script>
      

  2.   

    看了一下,密码应该是事先按加密算法自动生成的,而非用户手工设置的,
    getPass 函数对输入的密码进行解密验算,如果结果等于 -34 就通过,否则 Error,
    这样并不安全,只要读懂解密验算的算法就能自行构造密码,如输入 MVBa 就返回 OK!简单滴说,base 是一个编码表,包含了所有可能出现的密码字符,而数组索引为字符编号,
    在密码中,奇数位字符对应的字符编码为【正】,而偶数位字符对应的字符编码为【负】,
    只要密码的字符编码整体合计为 -34 即告 OK!例如:MVBa 就是 22-31+11-36 = -34只要根据这个规律可以任意构造密码了,最短密码为 0Y!L@_@K
        var base = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
        //document.write(base.join(""));
        var K = new Array();
        function getPass() {
            var goToPage = prompt("Password Required", "");
            if (goToPage == null || goToPage == "") {
                history.go(-1);
            } else {
                var pLength = goToPage.length;
                for (i = 0; i < pLength; i++) {
                    K[i] = goToPage.charAt(i);
                }
                var code = 0;
                var plus = 1;            for (i = 0; i < pLength; i++) {
                    for (x = 0; x < 62; x++) {
                        if (K[i] == base[x]) {
                            if (plus == 1) {
                                code = code + x;
                            } else {
                                code = code - x;
                            }
                            plus = plus * (-1);                    }
                    }
                }            if (code == -34) {                alert("OK");            } else {
                    alert("ERROR ");
                }
            }
        }
        getPass();
        // Input MVBa
        // OK