コード例 #1
0
ファイル: AUserModel.cs プロジェクト: burstas/rmps
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns></returns>
        public bool CaSignIn(string home, string code, string name, string pass)
        {
            string file = Path.Combine(home, CApp.AMON_CFG);
            if (!File.Exists(file))
            {
                return false;
            }

            DFEngine prop = new DFEngine();
            prop.Load(file);

            string data = prop.Get(CApp.AMON_CFG_DATA);
            if (!CharUtil.IsValidate(data, 344))
            {
                return false;
            }
            _Data = Convert.FromBase64String(data);

            string info = Digest(name, pass);
            if (info != prop.Get(CApp.AMON_CFG_INFO))
            {
                return false;
            }

            string main = prop.Get(CApp.AMON_CFG_MAIN);
            if (!Decrypt(name, code, pass, main))
            {
                return false;
            }

            _Lock = prop.Get(CApp.AMON_CFG_LOCK);

            this.Name = name;
            this.Code = code;
            this.DatHome = home;
            _Info = info;
            Look = "Default";
            Feel = "Default";
            return true;
        }
コード例 #2
0
ファイル: AUserModel.cs プロジェクト: burstas/rmps
        /// <summary>
        /// 设定安全口令
        /// </summary>
        /// <param name="oldPass"></param>
        /// <param name="secPass"></param>
        /// <returns></returns>
        public bool CaAuthSk(string oldPass, string secPass)
        {
            DFEngine prop = new DFEngine();
            prop.Load(Path.Combine(this.DatHome, CApp.AMON_CFG));

            // 已有口令校验
            string info = Digest(Name, oldPass);
            if (info != prop.Get(CApp.AMON_CFG_INFO))
            {
                return false;
            }

            // 生成加密密钥及字符空间
            byte[] t = new byte[72];
            byte[] a = Encoding.UTF8.GetBytes(Code);
            int i = 0;
            Array.Copy(a, 0, t, i, a.Length);
            i += a.Length;
            Array.Copy(_Salt, 0, t, i, _Salt.Length);
            i += _Salt.Length;
            Array.Copy(_Keys, 0, t, i, _Keys.Length);
            i += _Keys.Length;
            a = Encoding.UTF8.GetBytes(_Mask);
            Array.Copy(a, 0, t, i, a.Length);

            // 口令
            byte[] k = GenK(Name, Code, secPass);
            // 向量
            byte[] v = GenV(Name, Code, secPass);

            #region AES 加密
            AesManaged aes = new AesManaged();
            using (MemoryStream mStream = new MemoryStream())
            {
                using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateEncryptor(k, v), CryptoStreamMode.Write))
                {
                    cStream.Write(t, 0, t.Length);
                    cStream.FlushFinalBlock();
                    t = mStream.ToArray();
                }
            }
            aes.Clear();
            #endregion

            prop.Set(CApp.AMON_CFG_SAFE, Convert.ToBase64String(t));
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));
            return true;
        }
コード例 #3
0
ファイル: SignAc.cs プロジェクト: burstas/rmps
        /// <summary>
        /// 打开(&O)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MiOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdOpen = Main.OpenFileDialog;
            fdOpen.Filter = "阿木密码箱配置文件|*.cfg";
            fdOpen.FileName = CApp.AMON_CFG;
            fdOpen.InitialDirectory = _UserModel.SysHome;
            fdOpen.Multiselect = false;
            if (DialogResult.OK != fdOpen.ShowDialog(_Main))
            {
                return;
            }

            string path = fdOpen.FileName;
            if (!File.Exists(path))
            {
                Main.ShowAlert("无法访问您选择的文件!");
                return;
            }

            string file = (Path.GetFileName(path) ?? "").ToLower();
            if (CApp.AMON_CFG.ToLower() != file)
            {
                Main.ShowAlert(string.Format("请确认您选择的文件名是否为:{0}!", CApp.AMON_CFG));
                return;
            }

            DFEngine prop = new DFEngine();
            prop.Load(path);
            string name = prop.Get(CApp.AMON_CFG_NAME);
            string code = prop.Get(CApp.AMON_CFG_CODE);
            if (!CharUtil.IsValidateCode(code) || !CharUtil.IsValidate(name))
            {
                Main.ShowAlert("请确认您选择的数据路径是否正确!");
                return;
            }

            prop.Clear();
            string sysFile = Path.Combine(_UserModel.SysHome, CApp.AMON_SYS);
            prop.Load(sysFile);
            prop.Set(string.Format(CApp.AMON_SYS_CODE, name), code);
            path = Path.GetDirectoryName(path);
            if (path.StartsWith(Application.StartupPath))
            {
                path = path.Substring(Application.StartupPath.Length + 1);
            }
            prop.Set(string.Format(CApp.AMON_SYS_HOME, name), path);
            prop.Save(sysFile);
        }
コード例 #4
0
ファイル: SignIn.cs プロジェクト: burstas/rmps
        public void DoSignAc()
        {
            #region 用户判断
            _Name = TbName.Text;
            if (string.IsNullOrEmpty(_Name))
            {
                Main.ShowAlert("请输入【登录用户】!");
                TbName.Focus();
                return;
            }
            if (!CharUtil.IsValidateName(_Name))
            {
                Main.ShowAlert("【登录用户】应在 4 到 32 个字符之间,且仅能为大小写字母、下划线及英文点号!");
                TbName.Focus();
                return;
            }
            #endregion

            #region 口令判断
            _Pass = TbPass.Text;
            TbPass.Text = "";
            if (string.IsNullOrEmpty(_Pass))
            {
                Main.ShowAlert("请输入【登录口令】!");
                TbPass.Focus();
                return;
            }

            if (_Pass.Length < 4)
            {
                Main.ShowAlert("【登录口令】不能少于 4 个字符!");
                TbPass.Focus();
                return;
            }
            #endregion

            _SignAc.ShowWaiting();

            _Prop = new DFEngine();
            _Prop.Load(Path.Combine(_UserModel.SysHome, CApp.AMON_SYS));

            _Name = _Name.ToLower();
            string code = _Prop.Get(string.Format(CApp.AMON_SYS_CODE, _Name));
            _Home = _Prop.Get(string.Format(CApp.AMON_SYS_HOME, _Name));

            #region 已有用户首次登录
            if (!CharUtil.IsValidateCode(code))
            {
                //_Home = CApp.DIR_DATA;

                //WebClient client = new WebClient();
                //client.Credentials = CredentialCache.DefaultCredentials;
                //client.Headers["Content-type"] = "application/x-www-form-urlencoded";
                //client.Encoding = Encoding.UTF8;
                //client.UploadStringCompleted += new UploadStringCompletedEventHandler(SignIn_UploadStringCompleted);
                //client.UploadStringAsync(new Uri(CApp.SERVER_PATH), "POST", "&o=sin&d=" + _Name);

                _SignAc.HideWaiting();
                Main.ShowAlert("身份验证错误,请确认您的用户及口令输入是否正确!");
                TbName.Focus();
                return;
            }
            #endregion

            #region 已有用户正常登录
            if (!_Home.StartsWith(_UserModel.SysHome))
            {
                _Home = Path.Combine(_UserModel.SysHome, _Home);
            }
            if (!_UserModel.CaSignIn(_Home, code, _Name, _Pass))
            {
                _SignAc.HideWaiting();
                Main.ShowAlert("身份验证错误,请确认您的用户及口令输入是否正确!");
                TbPass.Focus();
                return;
            }

            _UserModel.Load();
            _SignAc.CallBack(CApp.IAPP_NONE);
            #endregion
        }
コード例 #5
0
ファイル: SignOl.cs プロジェクト: burstas/rmps
        public void DoSignAc()
        {
            #region 用户判断
            _Name = TbName.Text;
            if (string.IsNullOrEmpty(_Name))
            {
                Main.ShowAlert("请输入【登录用户】!");
                TbName.Focus();
                return;
            }
            if (!CharUtil.IsValidateName(_Name))
            {
                Main.ShowAlert("【登录用户】应在 4 到 32 个字符之间,且仅能为大小写字母、下划线及英文点号!");
                TbName.Focus();
                return;
            }
            #endregion

            #region 用户邮件
            _Mail = TbMail.Text;
            if (string.IsNullOrEmpty(_Mail))
            {
                Main.ShowAlert("请输入【电子邮件】!");
                TbMail.Focus();
                return;
            }
            if (!CharUtil.IsValidateMail(_Mail))
            {
                Main.ShowAlert("请输入一个有效的【电子邮件】!");
                TbMail.Focus();
                return;
            }
            #endregion

            #region 口令判断
            _Pass = TbPass1.Text;
            TbPass1.Text = "";
            if (string.IsNullOrEmpty(_Pass))
            {
                Main.ShowAlert("请输入【登录口令】!");
                TbPass1.Focus();
                return;
            }

            if (_Pass.Length < 4)
            {
                Main.ShowAlert("【登录口令】不能少于 4 个字符!");
                TbPass1.Text = "";
                TbPass2.Text = "";
                TbPass1.Focus();
                return;
            }

            if (_Pass != TbPass2.Text)
            {
                TbPass2.Text = "";
                Main.ShowAlert("您两次输入的口令不一致!");
                TbPass1.Focus();
                return;
            }
            TbPass2.Text = "";
            #endregion

            #region 路径判断
            _Root = TbPath.Text;
            if (string.IsNullOrEmpty(_Root))
            {
                _Root = CApp.DIR_DATA;
            }
            #endregion

            _SignAc.ShowWaiting();

            #region 本地用户判断
            _Name = _Name.ToLower();
            _Prop = new DFEngine();
            _Prop.Load(Path.Combine(_UserModel.SysHome, CApp.AMON_SYS));
            string home = _Prop.Get(string.Format(CApp.AMON_SYS_HOME, _Name));
            if (!string.IsNullOrEmpty(home))
            {
                _SignAc.HideWaiting();
                Main.ShowAlert(string.Format("已存在名为 {0} 的用户,请尝试其它用户名!", _Name));
                TbName.Focus();
                return;
            }
            #endregion

            // 在线注册
            WebClient client = new WebClient();
            client.Headers["Content-type"] = "application/x-www-form-urlencoded";
            client.Encoding = Encoding.UTF8;
            client.UploadStringCompleted += new UploadStringCompletedEventHandler(SignUpV_UploadStringCompleted);
            client.UploadStringAsync(new Uri(CApp.SERVER_PATH), "POST", "&o=rsa&m=0");
        }
コード例 #6
0
ファイル: SignPc.cs プロジェクト: burstas/rmps
        public void DoSignAc()
        {
            #region 用户判断
            string name = TbName.Text;
            if (string.IsNullOrEmpty(name))
            {
                Main.ShowAlert("请输入用户名!");
                TbName.Focus();
                return;
            }

            if (name.Length < 5)
            {
                Main.ShowAlert("用户名不能少于5个字符!");
                TbName.Focus();
                return;
            }

            if (!Regex.IsMatch(name, "^\\w{5,}$"))
            {
                Main.ShowAlert("用户名中含有非法字符!");
                TbName.Focus();
                return;
            }

            name = name.ToLower();
            string sysFile = Path.Combine(_UserModel.SysHome, CApp.AMON_SYS);
            _Prop = new DFEngine();
            _Prop.Load(sysFile);
            string home = _Prop.Get(string.Format(CApp.AMON_SYS_HOME, name));
            if (!string.IsNullOrEmpty(home))
            {
                Main.ShowAlert(string.Format("已存在名为 {0} 的用户,请尝试其它用户名!", name));
                return;
            }
            #endregion

            #region 口令判断
            string pass = TbPass1.Text;
            TbPass1.Text = "";
            if (string.IsNullOrEmpty(pass))
            {
                Main.ShowAlert("请输入登录口令!");
                TbPass1.Focus();
                return;
            }

            if (pass.Length < 4)
            {
                Main.ShowAlert("登录口令不能少于4个字符!");
                TbPass1.Text = "";
                TbPass2.Text = "";
                TbPass1.Focus();
                return;
            }

            if (pass != TbPass2.Text)
            {
                TbPass2.Text = "";
                Main.ShowAlert("您两次输入的口令不一致!");
                TbPass1.Focus();
                return;
            }
            TbPass2.Text = "";
            #endregion

            #region 路径判断
            home = TbPath.Text;
            if (string.IsNullOrEmpty(home))
            {
                Main.ShowAlert("请选择您的数据存放目录!");
                BtPath.Focus();
                return;
            }
            #endregion

            #region 代码
            string code = CApp.USER_AMON;
            if (Directory.Exists(Path.Combine(home, code)))
            {
                Main.ShowAlert(string.Format("指定路径下已存在名为 {0} 的目录!", code));
                return;
            }
            #endregion

            _SignAc.ShowWaiting();

            try
            {
                // 本地注册
                if (!_UserModel.CaSignUp(home, code, name, pass))
                {
                    pass = null;
                    _SignAc.HideWaiting();
                    Main.ShowAlert("系统异常,请稍后重试!");
                    return;
                }

                _Prop.Set(string.Format(CApp.AMON_SYS_CODE, name), _UserModel.Code);
                home = _UserModel.DatHome;
                if (home.StartsWith(Application.StartupPath))
                {
                    home = home.Substring(Application.StartupPath.Length + 1);
                }
                _Prop.Set(string.Format(CApp.AMON_SYS_HOME, name), home);
                _Prop.Save(sysFile);

                InitDat();
            }
            catch (Exception exp)
            {
                _SignAc.HideWaiting();
                Main.ShowAlert(exp.Message);
                return;
            }
        }