Esempio n. 1
0
        /// <summary>
        /// 增加 用户
        /// </summary>
        public static AjaxResult AddUser(NameValueCollection form)
        {
            try
            {
                DB.BeginTransaction();

                var entity = new CFUser();
                entity.Load(form);
                entity.LoginPassword = Encrypt.DESEncrypt(entity.LoginPassword);
                entity.UserID        = DB.Insert <CFUser>(entity);
                string roleid = form["RoleID"];
                SaveUserRole(roleid, entity.UserID);

                DB.CommitTransaction();
                DB.CloseTransaction();
                SignetInternet_BusinessLayer.SysLogHelper.AddLog(SysContext.CurrentUserName, "添加管理用户ID:" + entity.UserID, "添加-管理用户");
                return(AjaxResult.Success("保存成功"));
            }
            catch (Exception err)
            {
                DB.RollbackTransaction();
                DB.CloseTransaction();

                LogManager.WriteLog("Error", err.Message);
                return(AjaxResult.Error("系统错误:" + err.Message));
            }
        }
Esempio n. 2
0
        //保存前检查
        protected override bool ValidateBeforSave()
        {
            bool Validate = true
                            & LibraryTools.IsNotEmpBaseEdit(txtAccount, "账号不能为空!")
                            & LibraryTools.IsNotEmpBaseEdit(txtPassword, "密码不能为空!")
                            & LibraryTools.IsNotEmpBaseEdit(txxtPassword, "确认密码不能为空!")
                            & LibraryTools.IsNotEmpBaseEdit(txtUserName, "名称不能为空!");

            if (Validate == true)
            {
                if (!Object.Equals(txtPassword.EditValue, txxtPassword.EditValue))
                {
                    Msg.Warning("两次密码输入不一致,请重新输入!");
                    Validate = false;
                }
            }
            if (Validate == true)
            {
                //密码字段加密
                DataRow row = EditData.Tables[_bll.SummaryModel.TableName].Rows[0];

                if (row.HasVersion(DataRowVersion.Proposed))//只有修改之后的密码字段才进行加密
                {
                    if (!object.ReferenceEquals(row[dt_MyUser.Password, DataRowVersion.Current], row[dt_MyUser.Password, DataRowVersion.Proposed]))
                    {
                        row[dt_MyUser.Password] = Encrypt.DESEncrypt(row[dt_MyUser.Password].ToString());
                    }
                }
                txxtPassword.EditValue = EditData.Tables[_bll.SummaryModel.TableName].Rows[0][dt_MyUser.Password];
            }
            return(Validate);
        }
Esempio n. 3
0
        /// <summary>
        /// 更新 用户
        /// </summary>
        public static AjaxResult UpdateUser(NameValueCollection form)
        {
            try
            {
                DB.BeginTransaction();

                var entity = DB.From <CFUser>().Where(CFUser._.UserID == form["UserID"]).ToFirst();
                entity.Attach();

                entity.Load(form);
                entity.LoginPassword = Encrypt.DESEncrypt(entity.LoginPassword);
                DB.Update <CFUser>(entity);
                string roleid = form["RoleID"];
                SaveUserRole(roleid, entity.UserID);

                DB.CommitTransaction();
                DB.CloseTransaction();
                return(AjaxResult.Success("保存成功"));
            }
            catch (Exception err)
            {
                DB.RollbackTransaction();
                DB.CloseTransaction();

                LogManager.WriteLog("Error", err.Message);
                return(AjaxResult.Error("系统错误:" + err.Message));
            }
        }
Esempio n. 4
0
        private bool CalcMac(byte[] macBytes, byte[] mackey, ref byte[] MAC)
        {
            int p_len = macBytes.Length;

            int i, j, p;

            byte[] szBuffer   = new byte[8];
            byte[] gbszBufstr = new byte[10240];
            macBytes[9] |= 1;
            Array.Copy(macBytes, gbszBufstr, p_len);
            if (p_len % 8 != 0)
            {
                p = 1;
            }
            else
            {
                p = 0;
            }
            for (i = 0; i < (p_len / 8) + p; i++)
            {
                for (j = 0; j < 8; j++)
                {
                    szBuffer[j] ^= gbszBufstr[i * 8 + j];
                }
            }
            //Log.Debug("calc data:" + Utility.bcd2str(szBuffer,szBuffer.Length));
            MAC = Encrypt.DESEncrypt(szBuffer, mackey);
            return(true);
        }
Esempio n. 5
0
 private void Finish()
 {
     pin = GetElementById(mId).GetAttribute("value").PadRight(8, '0');
     //pin = "84383500";
     byte[] EncrPin = Encrypt.DESEncrypt(Encoding.Default.GetBytes(pin), mPinKey);
     CommonData.BankPassWord = Utility.bcd2str(EncrPin, EncrPin.Length);
     //StartActivity("德化燃气正在交易");
     GotoNext();
 }
Esempio n. 6
0
    /// <summary>
    /// 用户登录
    /// </summary>
    /// <returns></returns>
    public static bool UserLogin(string username, string password)
    {
        string tempPass     = Encrypt.DESEncrypt(password);
        var    loginSuccess = DB.From <CFUser>().Where(CFUser._.LoginName == username && CFUser._.LoginPassword == tempPass).Any();

        if (loginSuccess)
        {
            var user = DB.From <CFUser>().Where(CFUser._.LoginName == username && CFUser._.LoginPassword == tempPass).ToFirst();


            var roles = DB.From <CFUserRole>().Where(CFUserRole._.UserID == user.UserID).ToList();

            var roleids = Array.ConvertAll <int, string>(roles.Select(c => c.RoleID).ToArray(), c => c.ToStr());

            string regDeptIds   = string.Empty;
            string carveCorpIds = string.Empty;

            //UserInfoHelper helper = new UserInfoHelper();

            DataTable dt = null;


            SysContext.CurrentUserID = user.UserID;

            SysContext.CurrentDeptID = user.DeptID;

            SysContext.CurrentEmployeeID = user.EmployeeID;

            SysContext.CurrentSupplierID = user.SupplierID;

            if (user.LastLoginTime.HasValue)
            {
                SysContext.CurrentUserLastLoginTime = user.LastLoginTime.Value.ToString();
            }

            if (user.LoginName.HasValue())
            {
                SysContext.CurrentUserName = user.LoginName;
            }

            SysContext.CurrentUserTitle = user.Title;

            SysContext.CurrentRealName = user.RealName;

            SysContext.CurrentRoleID = string.Join(",", roleids);

            UserInfoHelper helper = new UserInfoHelper();
            if (DataPrivilegeRule.IsAdministrator(user.UserID, roleids))
            {
                dt = helper.GetRegDeptList();
                foreach (DataRow row in dt.Rows)
                {
                    regDeptIds += ",'" + row["PSID"].ToString() + "'";
                }

                dt = helper.GetCummunityList();
                foreach (DataRow row in dt.Rows)
                {
                    carveCorpIds += ",'" + row["LSID"].ToString() + "'";
                }
            }
            else
            {
                dt = helper.GetUserRegRelationList(user.UserID.ToString());
                foreach (DataRow row in dt.Rows)
                {
                    regDeptIds += ",'" + row["t_ad_reg_dept_id"].ToString() + "'";
                }

                dt = helper.GetCummunityListByUser(user.UserID.ToString());
                foreach (DataRow row in dt.Rows)
                {
                    carveCorpIds += ",'" + row["t_ad_reg_dept_id"].ToString() + "'";
                }
            }

            if (!string.IsNullOrEmpty(regDeptIds))
            {
                regDeptIds = regDeptIds.Substring(1);
                SysContext.CurrentAreaIDs = regDeptIds;
            }
            else
            {
                regDeptIds = "'undefined'";
                SysContext.CurrentAreaIDs = regDeptIds;
            }

            if (!string.IsNullOrEmpty(carveCorpIds))
            {
                carveCorpIds = carveCorpIds.Substring(1);
                SysContext.CurrentCarveIDs = carveCorpIds;
            }
            else
            {
                carveCorpIds = "'undefined'";
                SysContext.CurrentCarveIDs = carveCorpIds;
            }

            LogManager.WriteLog("USER", user.RealName + " 登录系统");

            user.Attach();
            user.LastLoginTime = DateTime.Now;
            DB.Update <CFUser>(user);

            string  currentIp = LigerRM.Common.Global.GlobalHelper.GetIPAddress();
            DataSet ds        = DB.ExecuteDataSet("select * from CF_UserLoginStatus where UserID=" + SysContext.CurrentUserID.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                DB.ExecuteDataSet("Update CF_UserLoginStatus set LoginTime='" + DateTime.Now.ToString() + "', LoginIP='" + currentIp + "', IsOnline=1 where UserID=" + SysContext.CurrentUserID.ToString());
            }
            else
            {
                DB.ExecuteDataSet("insert into CF_UserLoginStatus values (" + SysContext.CurrentUserID.ToString() + ",'" + DateTime.Now.ToString() + "','" + currentIp + "',1) ");
            }
        }
        return(loginSuccess);
    }
Esempio n. 7
0
 private byte[] DesEncrypt(byte[] originalData, byte[] key)
 {
     byte[] encryptData = new byte[0];
     encryptData = Encrypt.DESEncrypt(originalData, key);
     return(encryptData);
 }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (uc == null)
            {
                return;
            }
            if (String.IsNullOrEmpty(txt_DBCode.Text))
            {
                txt_DBCode.ErrorText = "数据库别名不能为空!";
                return;
            }
            if (String.IsNullOrEmpty(txt_DBText.Text))
            {
                txt_DBText.ErrorText = "数据库名不能为空!";
                return;
            }

            //判断编号是否存在
            if (ConvertLib.ToString(txt_DBCode.EditValue) != "")
            {
                if (bll.DBCodeExists(txt_DBCode.EditValue.ToString()) == true)
                {
                    txt_DBCode.ErrorText = "数据库编号已经存在!";
                    return;
                }
            }


            var db = uc.DoConfig();

            if (db == null)
            {
                return;
            }

            INIDBConfig i            = new INIDBConfig();
            string      ProviderName = db.ProviderName;
            string      ConStr       = db.GetConnectionStr();
            //string ConnStr = Encrypt.DESEncrypt(db.GetConnectionStr(), Globals.KeyConnectionStr);

            var fac = System.Data.Common.DbProviderFactories.GetFactory(ProviderName);

            using (var conn = fac.CreateConnection())
            {
                conn.ConnectionString = ConStr;
                conn.Open();



                DataTable dt  = bll.GetTableStruct(sys_DataBaseList._TableName);
                DataRow   row = dt.Rows.Add();
                row[sys_DataBaseList.DBCode]         = txt_DBCode.EditValue;
                row[sys_DataBaseList.DBDisplayText]  = txt_DBText.EditValue;
                row[sys_DataBaseList.DBProviderName] = ProviderName;
                row[sys_DataBaseList.DBServer]       = conn.DataSource;
                row[sys_DataBaseList.DBName]         = conn.Database;
                row[sys_DataBaseList.DBConnection]   = Encrypt.DESEncrypt(ConStr, Globals.KeyConnectionStr);
                bll.Update(dt);
                Data = dt;
                conn.Close();
            }


            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 private string PwdEncrypt(string Pwd)
 {
     return(Encrypt.DESEncrypt(Pwd));
 }
Esempio n. 10
0
        protected void DoSignInSucc()
        {
            string time = RecvPackage.GetString(12); //时间
            string date = RecvPackage.GetString(13); //日期

            //SetBatchNo(RecvPackage.GetString(37).Substring(2, 6));//记录批次号

            byte[] bField60 = new byte[0];
            bField60 = Utility.str2Bcd(RecvPackage.GetString(60));
            //bField60 = RecvPackage.GetArrayData(60);
            byte[] EPinkey = new byte[KeyLength];
            byte[] EMackey = new byte[KeyLength];
            Array.Copy(bField60, 0, EPinkey, 0, KeyLength);
            Array.Copy(bField60, 8, EMackey, 0, KeyLength);
            KeyManager.SetEnMacKey(SectionName, EMackey);
            KeyManager.SetEnPinKey(SectionName, EPinkey);
            byte[] bTerminalNo = Encoding.Default.GetBytes(GetTerminalNo());

            byte[] PinKey = null, WorkKey = null;
            if (EnType == EncryptType.Soft)
            {
                byte[] MasterKey = GetSoftMasterKey();
                if (DType == DesType.Des)
                {
                    byte[] EPinkeytmp = EPinkey;
                    byte[] EMackeytmp = EMackey;

                    byte[] tmp = Encrypt.DESEncrypt(EPinkeytmp, MasterKey);
                    PinKey = Encrypt.DESDecrypt(tmp, bTerminalNo);

                    tmp     = Encrypt.DESEncrypt(EMackeytmp, MasterKey);
                    WorkKey = Encrypt.DESDecrypt(tmp, bTerminalNo);
                }
                else if (DType == DesType.TripleDes)
                {
                    PinKey  = Encrypt.DES3Decrypt(EPinkey, MasterKey);
                    WorkKey = Encrypt.DES3Decrypt(EMackey, MasterKey);
                }
            }
            else
            {
                PinKey  = new byte[KeyLength];
                WorkKey = new byte[KeyLength];
                Esam.SetWorkmode(Esam.WorkMode.Encrypt);

                byte[] tempkey = new byte[8];

                Esam.UserEncrypt(GetKeyIndex(), EPinkey, KeyLength, tempkey);
                //Esam.Encrypt(EPinkey, 8, tempkey);
                PinKey = Encrypt.DESDecrypt(tempkey, bTerminalNo);

                Esam.UserEncrypt(GetKeyIndex(), EMackey, KeyLength, tempkey);
                //Esam.Encrypt(EMackey, 8, tempkey);
                WorkKey = Encrypt.DESDecrypt(tempkey, bTerminalNo);

                Esam.SetWorkmode(Esam.WorkMode.Default);
            }
            KeyManager.SetDeMacKey(SectionName, WorkKey);
            KeyManager.SetDePinKey(SectionName, PinKey);
            Log.Info("download pinKey:" + Utility.bcd2str(PinKey, PinKey.Length));
            Log.Info("download macKey:" + Utility.bcd2str(WorkKey, WorkKey.Length));
            //更新当前机器时间
            int      year  = System.DateTime.Now.Year;
            int      month = Convert.ToInt32(date.Substring(4, 2));
            int      day   = Convert.ToInt32(date.Substring(6, 2));
            int      hour  = Convert.ToInt32(time.Substring(0, 2));
            int      mi    = Convert.ToInt32(time.Substring(2, 2));
            int      ss    = Convert.ToInt32(time.Substring(4, 2));
            DateTime newDt = new DateTime(year, month, day, hour, mi, ss);

#if !DEBUG
            Utility.SetSysTime(newDt);
#endif
//            }
        }