/// <summary> /// 对比验证信息 /// </summary> /// <param name="str"></param> /// <returns></returns> public bool ConfirmVcStr(string str) { string _VcWxCode = UtilityFun.GetCookie("_vcKey", false); str = UtilityCryptography.AESDecrypt(str); return(string.Equals(_VcWxCode, str, StringComparison.CurrentCultureIgnoreCase)); }
protected void Page_Load(object sender, EventArgs e) { try { string _VcCharCookieKey = UtilityFun.ReqStr("vcCharCookieKey", ""); if (_VcCharCookieKey != "") { _VcCharCookieKey = UtilityCryptography.AESDecrypt(_VcCharCookieKey); //得到 _vcWxCodeChar12060600 int width = UtilityFun.ReqNum("width", 178); int height = UtilityFun.ReqNum("height", 136); string _VcChar = Session[_VcCharCookieKey].ToString(); if (string.IsNullOrEmpty(_VcChar)) { HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write("error1."); HttpContext.Current.Response.End(); } MemoryStream ms; List <Position> list; Position _Selected; Draw _Draw = new Draw(); //这里还需要向couchBase里存一次,存验证码具体的字符和位置 _Draw.DrawVc(width, height, false, _VcChar, out ms, out list, out _Selected); if (_Selected != null && _Selected.ChineseChar != "") { new VcBLL().SetVcCodeAuth(_Selected); HttpContext.Current.Response.ContentType = "image/png"; HttpContext.Current.Response.BinaryWrite(ms.ToArray()); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write("error1."); HttpContext.Current.Response.End(); } } else { HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write("error2."); HttpContext.Current.Response.End(); } } catch { HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write("error3."); HttpContext.Current.Response.End(); } }
public string GetResult() { string _Result = "\"code\":-3"; string _Action = UtilityFun.ReqStrSQL("action", ""); //是否get方式请求 bool _IsGet = true; //是否通过http请求 bool _IsHttp = false; switch (_Action) { #region 获取已请求的验证码次数 case "getVcCodeReqTimes": try { string _Username = UtilityFun.ReqStr("username", ""); // 15802794545 string _Key = UtilityCryptography.Encrypt(_Username, 2); if (string.IsNullOrEmpty(_Key)) { _Result = "\"state\":0"; // } else { //int _ReqTimes = RequestLimit.CheckVcCodeRequestTimes( _Key ); //_Result = GetJsonStr( _ReqTimes >= BLLVar.VcCodeLimitTimes - 1 ? 1 : 0 ); } } catch (Exception) { _Result = "\"state\":-2"; } break; #endregion #region 新版验证码,获取一个字符 case "getVcChar": #region try { string _Key = UtilityFun.ReqStrSQL("key", ""); string _IsCheck = UtilityFun.ReqStrSQL("ischeck", ""); //这个参数在注册功能没用上,后续观望 if (_Key != "" && (UtilityFun.IsMobile(_Key) || UtilityFun.IsEmail(_Key))) { //存入couchbase string couchBasekey = UtilityCryptography.Encrypt(_Key, 2); int reqTimes = 1;//RequestLimit.CheckVcCodeRequestTimes( couchBasekey ); if (reqTimes >= 2) { _Result = GetJsonStr(1); } else { if (_IsCheck == "1") { _Result = GetJsonStr(0, 0, ""); } else { string _VcChar = Text.GetVcChar(); string _VcCharCookieKey = "_vcWxCodeChar" + DateTime.Now.ToString("ssffffff"); //CouchBaseClient _Couch = new CouchBaseClient( 2 ); //_Couch.SetObject( _VcCharCookieKey, _VcChar, 10 * 60 * 1000d ); UtilityFun.SetCookie(_VcCharCookieKey, _VcChar, "", 10, false); //写入cookie UtilityFun.SetCookie("_vcKey", couchBasekey, "", 10, false); string _EncrypedVcCharCookieKey = UtilityCryptography.AESEncrypt(_VcCharCookieKey); _Result = string.Format("\"state\":{0},\"str\":\"{1}\",\"vcChar\":\"{2}\"", 0, _EncrypedVcCharCookieKey, _VcChar); } } } else { _Result = GetJsonStr(2); } } catch (Exception) { _Result = "\"state\":-2"; } #endregion break; #endregion #region 图形验证码的比较 case "VcCompare": try { string _Key = UtilityFun.GetCookie("_vcKey", false); if (!string.IsNullOrEmpty(_Key)) { int reqTimes = 1; //RequestLimit.CheckVcCodeRequestTimes( _Key ); if (reqTimes >= 2) { _Result = GetJsonStr(1, 0); //超出请求次数限制 } else { double x = double.Parse(UtilityFun.ReqStrSQL("x", "0")); double y = double.Parse(UtilityFun.ReqStrSQL("y", "0")); int fontSize = UtilityFun.ToInt32(ConfigurationManager.AppSettings["VcCodeFontSize"]); fontSize = fontSize <= 0 ? 1 : fontSize; Position p = new Position { XDis = x, YDis = y }; bool confirmResult = new VcBLL().ConfirmVcCodeAuth(p, fontSize); //using ( VcBLL _IBL = new VcBLL() ) //{ // confirmResult = new VcBLL().ConfirmVcCodeAuth( p, fontSize ); //} //if ( confirmResult ) //{ // RequestLimit.UpdateVcCodeRequestTimes( _Key, 0 ); //} //else //{ // RequestLimit.UpdateVcCodeRequestTimes( _Key, BLLVar.VcCodeOverTimes * 60 * 1000d ); //} //AESEncrypt(_Key),对md5字符串再次进行AES加密,没有问题。 _Result = confirmResult ? GetJsonStr(0, 0, UtilityCryptography.AESEncrypt(_Key)) : GetJsonStr(1, 1, ""); //点击位置错误 } } else { _Result = GetJsonStr(2); } } catch { _Result = GetJsonStr(-2); } break; #endregion } //设置过小压缩后反会增大 if (_Result.Length < 120) { UtilityFun.SetUnZip(); } if (_IsHttp) { return(_Result); } return(_IsGet ? Exit(_Result) : "{" + _Result + "}"); }