/// <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)); }
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> /// 比对验证码 /// 正确之后失效 /// </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); }
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 + "}"); }