function login(){ var userName = document.getElementById("userName").value.replace(/^\s+|\s+$/g,""); var password = document.getElementById("password").value.replace(/^\s+|\s+$/g,""); var validationCode = document.getElementById("validate").value.replace(/^\s+|\s+$/g,""); if(validation(userName, password, validationCode)){ if(checkSpecificKey(userName)){ var key = CryptoJS.enc.Utf8.parse(validationCode+validationCode+validationCode.substring(0,4)); var passwordjm = CryptoJS.enc.Utf8.parse(password); var encrypted = CryptoJS.AES.encrypt(passwordjm, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}); password = encrypted.toString(); jQuery.ajax({ url:contextPath+"/portal/login.do", contentType:"application/json", data:JSON.stringify({"validationCode":validationCode,"userName":userName,"password":password}), type:"post", dataType:"json", success:function(ret){ if(ret.verification === "true"){ if(ret.status=="1"){ window.parent.parent.location.replace(ret.redictPagePath); }else if(ret.status=="2"){ window.location.href=encodeURI(ret.redictPagePath+"?validationInfo="+ret.exception+"&userName="+userName+"&password="+password); window.event.returnValue = false; if (window.event.preventDefault) window.event.preventDefault(); }else if(ret.status=="3"){ window.location.href=encodeURI(ret.redictPagePath+"?validationInfo="+ret.exception+"&userName="+userName+"&password="+password); window.event.returnValue = false; if (window.event.preventDefault) window.event.preventDefault(); }else{ window.location.href=encodeURI(ret.redictPagePath+"?exception="+HTMLEncode(ret.exception)); window.event.returnValue = false; if (window.event.preventDefault) window.event.preventDefault(); } }else if(ret.verification === "overtime") { document.getElementById( "sp" ).innerHTML = "验证码失效,请重新输入验证码!"; document.getElementById( "sp" ).style.display = "inline"; updateValidationCode(); }else if(ret.verification === "sysErr") { window.location.href=encodeURI(ret.redictPagePath+"?validationInfo=请正确输入账号信息"); window.event.returnValue = false; if (window.event.preventDefault) window.event.preventDefault(); }else { document.getElementById( "sp" ).innerHTML = "验证输入错误!"; document.getElementById( "sp" ).style.display = "inline"; updateValidationCode(); } }, error:function(exception){ } }); } } } function validation(userName,password,validationCode){ if(!userName){ alert("用户名不能为空(please input your userName)!"); return false; } if(!password){ alert("密码不能为空(please input your password)!"); return false; } if(!validationCode){ //@REVIEW 修改提示显示方式 与“验证码”错误相同 by lihui@primeton.com document.getElementById( "sp" ).innerHTML = "验证码不能为空!"; document.getElementById( "sp" ).style.display = "inline"; // alert("验证码不能为空(please input your validationCode)!"); return false; } return true; } //点击图片更换验证码 function updateValidationCode() { jQuery("#validationCode").attr("src",contextPath+"/validata/images?data="+new Date().getTime()); } function checkSpecificKey(e) { if (null == e || '' == e || undefined == e) { return; } var specialKey =new RegExp("[~'!#@$%^&*()-+_=:<>]"); var realkey = e; if (specialKey.test(realkey)) { alert('请勿输入特殊字符: ' + realkey); return false; } return true; }