Ejemplo n.º 1
0
        /// <summary>
        /// 显示保存的账号列表
        /// </summary>
        private void ShowSavedAccounts()
        {
            if (DataUtil.Config.accountList == null)
            {
                return;
            }
            DESHelper des = new DESHelper();

            cbUsername.Items.Clear();
            int cnt = 0;

            foreach (SysConfig.AccountList acc in DataUtil.Config.accountList)
            {
                if (acc.gameServer == cbGameServer.SelectedIndex)
                {
                    cbUsername.Items.Add(des.Decrypt(acc.username));
                    if (cnt == 0 || (DataUtil.Config.LastLoginAccount != "" && acc.username == DataUtil.Config.LastLoginAccount))
                    {
                        cbUsername.SelectedIndex = cnt;
                        tbPassword.Password      = des.Decrypt(acc.password);
                    }
                    cnt++;
                }
            }
            if (cnt == 0)
            {
                tbPassword.Password = "";
            }
        }
Ejemplo n.º 2
0
        public IMongoDatabase CreateDatabase(string dbName)
        {
            if (!string.IsNullOrEmpty(dbName))
            {
                DB_NAME = dbName;
            }

            MongoConfig config = Config.ConfigAccess <MongoConfig> .GetConfig();

            if (config == null || config.ConnectionList == null || config.ConnectionList.Count == 0)
            {
                throw new Exception("MongoConfig为空");
            }

            MongoConnection connection = config.ConnectionList.FindLast(x => x.DBName == DB_NAME);

            if (connection == null)
            {
                throw new Exception("connection为空");
            }

            MongoClientSettings mongoSetting = new MongoClientSettings();

            //设置连接超时时间
            mongoSetting.ConnectTimeout = new TimeSpan(config.ConnectionTimeout * TimeSpan.TicksPerSecond);
            var CONNECT_USER_ID = connection.UserName;
            var CONNECT_PWD     = string.Empty;

            if (!string.IsNullOrWhiteSpace(connection.PassWord))
            {
                DESHelper des = new DESHelper();
                // connection.PassWord DES 解密
                CONNECT_PWD = des.Decrypt(connection.PassWord);
            }
            //账号密码
            if (CONNECT_USER_ID.Length > 0 && CONNECT_PWD.Length > 0)
            {
                mongoSetting.Credentials = new List <MongoCredential>()
                {
                    MongoCredential.CreateMongoCRCredential(DB_NAME, CONNECT_USER_ID, CONNECT_PWD)
                };
            }
            var lstMongoConnHost = connection.Host.Split(new char[] { ',' });
            var lstMongoConnPort = connection.Port.Split(new char[] { ',' });
            var lstService       = lstMongoConnHost.Select(
                (t, i) => new MongoServerAddress(t, lstMongoConnPort.Length > i ? int.Parse(lstMongoConnPort[i])
                    : int.Parse(lstMongoConnPort[0]))).ToList();

            mongoSetting.Servers = lstService;
            //读写分离
            mongoSetting.ReadPreference = new ReadPreference(ReadPreferenceMode.Secondary);
            //设置最大连接数
            mongoSetting.MaxConnectionPoolSize = 50;

            //创建Mongo的客户端
            Client = new MongoClient(mongoSetting);

            //得到服务器端并且生成数据库实例
            return(Client.GetDatabase(DB_NAME));
        }
Ejemplo n.º 3
0
        private void cbUsername_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataUtil.Config.accountList == null || cbUsername.SelectedIndex < 0)
            {
                return;
            }
            DESHelper des = new DESHelper();

            foreach (SysConfig.AccountList acc in DataUtil.Config.accountList)
            {
                if (acc.gameServer == cbGameServer.SelectedIndex && des.Decrypt(acc.username) == cbUsername.Items[cbUsername.SelectedIndex].ToString())
                {
                    tbPassword.Password = des.Decrypt(acc.password);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public CustomMessage ActivationUser(string activationCode)
        {
            var message = new CustomMessage();

            try
            {
                var dbContext = DbContainer.GetDbContext();
                dbContext.Configuration.ValidateOnSaveEnabled = false;

                // 查询激活码的有效性
                var activationInfo = dbContext.Sys_Activation.Where(c => c.ActivationCode == activationCode).FirstOrDefault();
                if (activationInfo == null)
                {
                    throw new Exception("激活码不存在或已过期!");
                }

                string source = DESHelper.Decrypt(activationCode, Global.__KEY);
                if (string.IsNullOrEmpty(source))
                {
                    throw new Exception("激活码有误!请重新输入");
                }

                // 解码后的信息,包含用户名还有激活等级
                dynamic info            = JsonConvert.DeserializeObject <dynamic>(source);
                string  userName        = info.UserName;
                int     activationLevel = info.ActivationLevel;

                // 修改用户激活数据
                var userItem = (from u in dbContext.UserInfo
                                where u.UserName == userName
                                select u).FirstOrDefault();
                userItem.IsActivation    = true;
                userItem.ActivationLevel = activationLevel;
                userItem.ActivationDate  = DateTime.Now;

                // 删除掉临时保存的激活码
                dbContext.Sys_Activation.Remove(activationInfo);

                if (dbContext.SaveChanges() == 0)
                {
                    message.Status  = HttpStatus.Error;
                    message.Message = "修改错误";
                }

                message.Status  = HttpStatus.OK;
                message.Message = $"账号激活成功!到期日期为{ConvertExtensions.ToActivationDate(activationLevel)}后";
            }
            catch (Exception objException)
            {
                LogHelper.Error(objException);
                message.Status  = HttpStatus.Error;
                message.Message = objException.Message;
            }

            return(message);
        }
Ejemplo n.º 5
0
        public void EncrytpTest2()
        {
            var key = CryptoHelper.GenerateKey("*****@*****.**", 8);
            var iv  = CryptoHelper.GenerateIv(8);

            var cipher = DESHelper.Encrypt("cszfp.com", key, iv);

            var clear = DESHelper.Decrypt(cipher, key, iv);

            Assert.AreEqual("cszfp.com", clear);
        }
Ejemplo n.º 6
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string userdata = controllerContext.HttpContext.Request[bindingContext.ModelName];

            if (string.IsNullOrWhiteSpace(userdata))
            {
                return(string.Empty);
            }
            userdata = DESHelper.Decrypt(userdata);
            return(userdata);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 客户端缓存操作对象
        /// </summary>
        public IRedisClient GetClient()
        {
            if (_prcm == null)
            {
                CreateManager();
            }
            IRedisClient client = _prcm.GetClient();

            client.Password = DESHelper.Decrypt(Password);
            return(client);
        }
Ejemplo n.º 8
0
        public void EncryptTest()
        {
            var key = CryptoHelper.GenerateKey("*****@*****.**", 8);

            var strKey = Convert.ToBase64String(key);

            var cipher = DESHelper.Encrypt("cszfp.com", strKey);

            var clear = DESHelper.Decrypt(cipher, strKey);

            Assert.AreEqual("cszfp.com", clear);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 凭证验证
        /// </summary>
        /// <param name="certificate">凭证字符串</param>
        /// <returns>凭证验证结果</returns>
        public static CertificateResult Verify(string certificate)
        {
            CertificateResult result = new CertificateResult();

            try
            {
                //1.DES解密
                string   temp       = certificate.Replace(' ', '+');
                string   str        = DESHelper.Decrypt(temp);
                string[] strs       = str.Split('|');
                string   systemCode = strs[0];
                string   dbUser     = strs[1];
                string   dbPassword = strs[2];

                //2.数据库校验
                if (systemCode.IsNull())
                {
                    throw new Exception();
                }

                Database  db  = DatabaseFactory.CreateDatabase();
                DbCommand cmd = db.GetSqlStringCommand("select * from zydict.external_system_dict where system_code = :argSystemCode");
                db.AddInParameter(cmd, "argSystemCode", DbType.String, systemCode);

                DataTable table = db.ExecuteDataSet(cmd).Tables[0];
                if (table.Rows.Count <= 0)
                {
                    throw new Exception();
                }

                string dbUserTrue     = table.Rows[0]["DB_USER"].ToString().Trim();
                string dbPasswordTrue = table.Rows[0]["DB_PASSWORD"].ToString().Trim();

                if (dbUser != dbUserTrue || dbPassword != dbPasswordTrue)
                {
                    throw new Exception();
                }

                result.Success         = true;
                result.SystemCode      = systemCode;
                result.OrgCode         = table.Rows[0]["ORG_CODE"].ToString();
                result.DbConnectConfig = table.Rows[0]["DB_CONNECT_CONFIG"].ToString();
                result.DbUser          = dbUser;
                result.DbPassword      = dbPassword;
                result.DbType          = table.Rows[0]["DB_TYPE"].ToString();

                return(result);
            }
            catch (Exception ex)
            {
                throw new FaultException("00000", "验证的凭证无效!" + ex.Message);
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> OnGetAsync(String UserName, String Password)
        {
            string returnUrl = Url.Content("~/View/Index");

            try
            {
                // 清除现有的外部Cookie
                await HttpContext
                .SignOutAsync("Quick.Web.Cookie");
            }
            catch { }

            //跳转回主页面
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
            {
                return(LocalRedirect(returnUrl));
            }

            // *** !!! 在这里您可以验证用户 !!! ***
            // 在此示例中,我们仅登录用户(此示例始终登录用户)
            //
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, DESHelper.Decrypt(UserName)),
                new Claim(ClaimTypes.Role, "Administrator")
            };
            var claimsIdentity = new ClaimsIdentity(claims, "Quick.Web.Cookie");
            var authProperties = new AuthenticationProperties
            {
                IsPersistent = true,
                RedirectUri  = this.Request.Host.Value,
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(30)
            };

            try
            {
                await HttpContext.SignInAsync(
                    "Quick.Web.Cookie",
                    new ClaimsPrincipal(claimsIdentity),
                    authProperties);

                returnUrl = Url.Content("~/Main");
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }

            return(LocalRedirect(returnUrl));
        }
Ejemplo n.º 11
0
            /// <summary>
            /// 3DES 解密
            /// </summary>
            /// <param name="decryptString">待解密密文</param>
            /// <param name="decryptKey1">密匙1(长度必须为8位)</param>
            /// <param name="decryptKey2">密匙2(长度必须为8位)</param>
            /// <param name="decryptKey3">密匙3(长度必须为8位)</param>
            /// <returns></returns>
            public static string Decrypt(string decryptString, string decryptKey1, string decryptKey2, string decryptKey3)
            {
                string returnValue;

                try
                {
                    returnValue = DESHelper.Decrypt(decryptString, decryptKey1);
                    returnValue = DESHelper.Decrypt(returnValue, decryptKey2);
                    returnValue = DESHelper.Decrypt(returnValue, decryptKey3);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return(returnValue);
            }
        public async Task <bool> Handle(OperationHouseBackInfoEvent @event)
        {
            try
            {
                Console.WriteLine("\n日志消费:" + @event.ToJson() + "\n\n");
                var json  = DESHelper.Decrypt(@event.HouseBackupInfo.Data, "cbs_5i5j_2021");
                var model = json.ToObject <HouseBackupDto>();
                ;

                var VerifyRes = new VerifyApplyResultDto()
                {
                    HouseId           = model.HouseId,
                    CertificateNumber = model.CertificateNumber,
                    VerifyApplyNumber = "123456123456",
                    ProcessStatus     = "核验通过",
                    Reason            = "",
                    VerificationTime  = DateTime.Now,
                    FilePath          = "SHPTS000068153.jpg",
                    Reg_Id            = "111111"
                };
                json = VerifyRes.ToJson();

                var encryptString = DESHelper.Encrypt(json, "cbs_5i5j_2021");

                var res = new VerifyApplyResult()
                {
                    Data = encryptString
                };

                _eventBus.Publish("ex.gims.verifyapplyresult.dev", nameof(OperationVerifyApplyResultEvent), "qu.gims.verifyapplyresult.vplues.dev", res.ToJson());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                var re_json = @event.ToJson();
                _eventBus.Publish("ex.vplues.housebackup.dev", nameof(OperationHouseBackInfoEvent), "qu.vplues.housebackup.gims.dev", re_json);
            }

            return(await Task.FromResult(true));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <param name="content"></param>
        /// <param name="checkDate">是否校验时间</param>
        /// <returns></returns>
        public static string Get(string content, bool checkDate = true)
        {
            string result = string.Empty;
            var    auth   = DESHelper.Decrypt(content);
            var    token  = auth.Split('|');

            if (token.Length >= 1)
            {
                if (checkDate)
                {
                    var date = DateTime.Parse(token[1]);
                    if ((DateTime.Now - date).Seconds < 12 * 60 * 60)
                    {
                        result = token[0];
                    }
                }
                else
                {
                    result = token[0];
                }
            }
            return(result);
        }
Ejemplo n.º 14
0
        public static OracleConnection Connect()
        {
            //连接缓冲池配置

            /* *
             *  Connection Lifetime  销毁时间,默认0
             *  Connection Reset     是否复位,默认true
             *  Enlist               是否参与事务,默认true
             *  Max Pool Size        最大链接数,默认100
             *  Min Pool Size        最小链接数,默认0
             *  Pooling              是否启用链接缓冲,默认true
             * */
            string connectString = ConfigurationManager.ConnectionStrings["database"].ConnectionString;

            connectString = DESHelper.Decrypt(connectString); //解密
            OracleConnection connect = new OracleConnection(connectString);

            //连接数据库
            connect.Open();


            return(connect);
        }
Ejemplo n.º 15
0
        private void mainWeb_LoadCompleted(object sender, NavigationEventArgs e)
        {
            if (styleSheetApplied)
            {
                return;
            }
            var document = mainWeb.Document as HTMLDocument;

            if (document == null)
            {
                return;
            }

            //抽取Flash,应用CSS样式
            IHTMLElement gameFrame = null;

            if (DataUtil.Game.gameServer == (int)GameInfo.ServersList.American || DataUtil.Game.gameServer == (int)GameInfo.ServersList.AmericanR18)
            {
                gameFrame = document.getElementById("game_frame");
                if (gameFrame != null)
                {
                    mainWeb.Navigate(Convert.ToString(gameFrame.getAttribute("src")));
                    return;
                }
                else
                {
                    gameFrame = document.getElementById("externalContainer");
                }
            }
            else
            {
                gameFrame = document.getElementById("game_frame");
            }
            if (gameFrame != null)
            {
                var target = gameFrame?.document as HTMLDocument;
                if (target != null)
                {
                    if (DataUtil.Game.gameServer == (int)GameInfo.ServersList.American || DataUtil.Game.gameServer == (int)GameInfo.ServersList.AmericanR18)
                    {
                        target.createStyleSheet().cssText = DataUtil.Config.sysConfig.userCSSAmerican;
                    }
                    else
                    {
                        target.createStyleSheet().cssText = DataUtil.Config.sysConfig.userCSS;
                    }
                    styleSheetApplied = true;
                    MiscHelper.AddLog("抽取Flash样式应用成功!", MiscHelper.LogType.System);
                }
            }

            //自动登录相关
            if (!loginSubmitted && DataUtil.Config.currentAccount.username != null && DataUtil.Config.currentAccount.username.Trim() != "")
            {
                IHTMLElement username = null;
                IHTMLElement password = null;
                if (DataUtil.Game.gameServer == (int)GameInfo.ServersList.American || DataUtil.Game.gameServer == (int)GameInfo.ServersList.AmericanR18)
                {
                    username = document.getElementById("s-email");
                    password = document.getElementById("s-password");
                }
                else
                {
                    username = document.getElementById("login_id");
                    password = document.getElementById("password");
                }

                if (username == null || password == null)
                {
                    return;
                }

                DESHelper des = new DESHelper();

                username.setAttribute("value", des.Decrypt(DataUtil.Config.currentAccount.username));
                password.setAttribute("value", des.Decrypt(DataUtil.Config.currentAccount.password));

                if (DataUtil.Config.currentAccount.username.Trim() == "" || DataUtil.Config.currentAccount.password == "")
                {
                    loginSubmitted = true;
                    return;
                }

                //点击登录按钮
                if (DataUtil.Game.gameServer == (int)GameInfo.ServersList.American || DataUtil.Game.gameServer == (int)GameInfo.ServersList.AmericanR18)
                {
                    IHTMLElement autoLogin = document.getElementById("autoLogin");
                    IHTMLElement login     = document.getElementById("login-button");
                    if (autoLogin != null)
                    {
                        autoLogin.click();
                    }
                    if (login != null)
                    {
                        login.click();
                        loginSubmitted = true;
                    }
                }
                else
                {
                    foreach (IHTMLElement element in document.all)
                    {
                        if (Convert.ToString(element.getAttribute("value")) == "ログイン")
                        {
                            element.click();
                            loginSubmitted = true;
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 读取当前的登录用户
 /// </summary>
 /// <returns></returns>
 public OperatorModel GetCurrent()
 {
     return(LoginProvider == "Cookie" ? DESHelper.Decrypt(WebHelper.GetCookie(LoginUserKey)).ToEntity <OperatorModel>() : DESHelper.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToEntity <OperatorModel>());
 }