// Use this for initialization void Start() { if (instance == null) { instance = this; } }
/// <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)); }
void burn(float speed) { if (!isburning) { isburning = true; Particle.Play(); spriteRenderer.color = new Color(255f, 255f, 255f, 0); } if (currentFuel > 0)//update burn { currentFuel = currentFuel - Time.deltaTime * speed; float size = UtilityFun.Mapping(currentFuel, 0f, BurningFuel, 0f, 0.45f); ParticleSystem.MainModule main = Particle.main; main.startSize = size; } else // stop burn { ResetBurn(); } }
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 bool ConfirmVcCodeAuth(Position vcCode, int fontSize) { bool _Result = false; try { string _Key = UtilityFun.GetCookie("_vcWxCode", true); if (_Key != "" && fontSize > 0) { string _OldCodeStr = HttpContext.Current.Session[_Key].ToString(); if (string.IsNullOrEmpty(_OldCodeStr)) { UtilityFile.AddLogErrMsg("_vcWxCode", "_OldCodeStr is null, CouchbaseKey code is " + _Key + ", ip is " + UtilityFun.GetUserIP()); } else { Position _OldCode = new Position(); string[] _Temp = _OldCodeStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //_Temp肯定Length为3 _OldCode.XDis = int.Parse(_Temp[1]); _OldCode.YDis = int.Parse(_Temp[2]); _OldCode.ChineseChar = _Temp[0];// 汉字也需要比较 double dis = Position.GetDistanceBetweenPositions(vcCode, _OldCode); if (dis <= (double)fontSize / 2) { _Result = true; //这两个不要清空,因为在登录等业务里,残留的cookie的value值 和 _CouchBase中的value值还会被当成验证信息。 这两个等其自然失效 //_Couch.RemoveObject(_Key); //UtilityFun.DelCookie("_vcWxCode", ""); } else { UtilityFile.AddLogErrMsg("_vcWxCode", "key is " + _Key + ", CouchbaseKey code is " + _Key + ", ip is " + UtilityFun.GetUserIP()); } } } else { //考虑到部分用户可能不支持Cookies,在没有检测功能情况下,先让用户通过。 _Result = true; UtilityFile.AddLogErrMsg("_vcWxCode", "key is null, submit code is " + vcCode.ToString() + ", ip is " + UtilityFun.GetUserIP()); } } catch (Exception ex) { _Result = false; UtilityFile.AddLogMsg("BLLUser.ConfirmVcCodeAuth抛出异常:" + ex.Message); } return(_Result); }
/// <summary> /// 输出json结果 /// </summary> /// <param name="json">json数据</param> /// <returns></returns> private string Exit(string json) { string _CallFun = UtilityFun.ReqStrSQL("fun", ""); if (_CallFun == "") { HttpContext.Current.Response.ContentType = "application/json"; return("{" + json + "}"); } else { return(string.Format("{0}({{{1}}})", _CallFun, json)); } }
/// <summary> /// 比对验证码 /// 正确之后失效 /// </summary> /// <param name="authCode">提交的验证码</param> /// <returns></returns> public bool ConfirmAuth(string authCode) { bool _Result = false; try { string _Key = UtilityFun.GetCookie("_login", false); if (_Key != "") { //CouchBaseClient _Couch = new CouchBaseClient(); //string _OldCode = _Couch.GetObject<string>( _Key ); //if ( _OldCode != null && _OldCode.ToLower() == authCode.ToLower() ) //{ // _Result = true; // _Couch.RemoveObject( _Key ); // UtilityFun.DelCookie( "_login", "" ); //} //else //{ // UtilityFile.AddLogErrMsg( "login", "key is " + _Key + ", submit code is " + authCode + ", org code is " + _OldCode + ", ip is " + UtilityFun.GetUserIP() ); //} //_Couch = null; string _OldCode = HttpContext.Current.Session[_Key].ToString(); if (_OldCode != null && _OldCode.ToLower() == authCode.ToLower()) { _Result = true; HttpContext.Current.Session[_Key] = null; UtilityFun.DelCookie("_login", ""); } } else { //考虑到部分用户可能不支持Cookies,在没有检测功能情况下,先让用户通过。 _Result = true; } } catch (Exception ex) { _Result = false; UtilityFile.AddLogMsg("BLLUser.ConfirmAuth抛出异常:" + ex.Message); } return(_Result); }
/// <summary> /// 更新图形验证码 /// </summary> /// <returns></returns> public bool SetVcCodeAuth(Position vcCode) { bool _Result = true; try { string _Key = "vcWxCode" + DateTime.Now.ToString("ssffffff"); string _Value = vcCode.ChineseChar + "," + vcCode.XDis + "," + vcCode.YDis; //CouchBaseClient _Couch = new CouchBaseClient(); //_Result = _Couch.SetObject( _Key, _Value, 10 * 60 * 1000d ); HttpContext.Current.Session[_Key] = _Value; UtilityFun.SetCookie("_vcWxCode", _Key, "", 10, true); } catch (Exception ex) { _Result = false; UtilityFile.AddLogMsg("BLLUser.SetVcCodeAuth抛出异常:" + ex.Message); } return(_Result); }
/// <summary> /// 生成验证码 /// </summary> /// <param name="authCode">验证码</param> /// <returns></returns> public bool SetAuth(string authCode) { bool _Result = true; try { string _Key = "login" + DateTime.Now.ToString("ssffffff"); //CouchBaseClient _Couch = new CouchBaseClient(); //_Result = _Couch.SetObject( _Key, authCode, 600 * 1000d ); UtilityFun.SetCookie(_Key, authCode, "", 10, false); UtilityFun.SetCookie("_login", _Key, "", 10, false); //_Couch = null; } catch (Exception ex) { _Result = false; UtilityFile.AddLogMsg("BLLUser.SetAuth抛出异常:" + ex.Message); } return(_Result); }
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 + "}"); }
void Update() { float growValue = UtilityFun.Mapping(RainValue, RainMinValue, RainMaxValue, 0, 1); animator.Play("Tree01", 0, growValue); }